相关疑难解决方法(0)

参数中包含斜杠的网址?

题:

我正在创建一个wiki软件,基本上是维基百科/ mediawiki的克隆,但是在ASP.NET MVC中(MVC是重点,所以不建议我使用ScrewTurn).

现在我有一个问题:

我使用此路由映射来路由URL,如:http:
//en.wikipedia.org/wiki/ASP.NET

        routes.MapRoute(
            "Wiki", // Routenname
            //"{controller}/{action}/{id}", // URL mit Parametern
            "wiki/{id}", // URL mit Parametern
            new { controller = "Wiki", action = "dbLookup", id = UrlParameter.Optional } // Parameterstandardwerte
        );
Run Code Online (Sandbox Code Playgroud)

现在它刚刚发生在我身上,可能会出现像'AS/400'这样的标题:http:
//en.wikipedia.org/wiki/AS/400

在整体上,还有这个(标题'Slash'):http:
//en.wikipedia.org/wiki//

这一个:http:
//en.wikipedia.org/wiki//dev/null

总的来说,维基百科似乎有一个有趣的标题列表,如:http://en.wikipedia.org/wiki/Wikipedia : Articles_with_slashes_in_title

如何正确制作此路线的路线?

编辑:
类似于:
如果URL以/ Wiki /开头,如果它不以/ wiki/Edit /(但不是/ Wiki/Edit)开头,则将所有其余URL作为Id传递.

编辑:
嗯,只是另一个问题:我如何路由这个:http:
//en.wikipedia.org/wiki/C&A

维基百科可以......

编辑:
根据维基百科,由于与wikitext语法的冲突,在页面标题中永远不能使用以下字符(DISPLAYTITLE也不支持):

# < > [ ] | { …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-routing

63
推荐指数
3
解决办法
4万
查看次数

URL中的URL编码斜杠

我的地图是:

routes.MapRoute(
   "Default",                                             // Route name
   "{controller}/{action}/{id}",                          // URL with params
   new { controller = "Home", action = "Index", id = "" } // Param defaults
);
Run Code Online (Sandbox Code Playgroud)

如果我使用URL http://localhost:5000/Home/About/100%2f200,则没有匹配的路由.我将URL更改为http://localhost:5000/Home/About/100然后再次匹配路由.

有没有简单的方法来处理包含斜杠的参数?其他转义值(空格%20)似乎有效.

编辑:

编码Base64对我有用.它使URL变得丑陋,但现在还可以.

public class UrlEncoder
{ 
    public string URLDecode(string  decode)
    {
        if (decode == null) return null;
        if (decode.StartsWith("="))
        {
            return FromBase64(decode.TrimStart('='));
        }
        else
        {
            return HttpUtility.UrlDecode( decode) ;
        }
    }

    public string UrlEncode(string encode)
    {
        if (encode == null) return null;
        string encoded = …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc urlencode asp.net-mvc-routing

56
推荐指数
5
解决办法
6万
查看次数

标签 统计

asp.net-mvc ×2

asp.net-mvc-routing ×2

c# ×1

urlencode ×1