在参数斜线的网址? [英] URLs with slash in parameter?
问题描述
问:
我创建一个wiki软件,维基百科/的MediaWiki基本上是一个克隆,但在ASP.NET MVC(MVC的是点,因此不建议我ScrewTurn)。
I am creating a wiki software, basically a clone of wikipedia/mediawiki, but in ASP.NET MVC (the MVC is the point, so don't recommend me ScrewTurn).
现在我有一个问题:
我用这个路由映射,路由的URL,如:
http://en.wikipedia.org/wiki/ASP.NET
I use this route mapping, to route a URL like:
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
);
现在,它只是发生在我,有可能会像'AS / 400的标题:
http://en.wikipedia.org/wiki/AS/400
Now it just occured to me, that there might be titles like 'AS/400':
http://en.wikipedia.org/wiki/AS/400
Incidentially,也有这个(标题'斜线'):
http://en.wikipedia.org/wiki//
Incidentially, there is also this one (title 'Slash'):
http://en.wikipedia.org/wiki//
和这一个:
http://en.wikipedia.org/wiki//dev/null
总体而言,维基百科似乎有有趣的标题像这样的列表:
<一href=\"http://en.wikipedia.org/wiki/Wikipedia:Articles_with_slashes_in_title\">http://en.wikipedia.org/wiki/Wikipedia:Articles_with_slashes_in_title
Overall, Wikipedia seems to have a list of interesting titles like this: http://en.wikipedia.org/wiki/Wikipedia:Articles_with_slashes_in_title
如何让我的路线是这样的路线是否正确?
How do I make routes like this route correctly ?
编辑:
喜欢的东西:
如果网址开头/维基/,如果它不以/维基/编辑开始/
(但不是/维基/编辑)
然后通过URL作为标识的所有的休息。
Something like:
If the URL starts with /Wiki/, and if it doesn't start with /wiki/Edit/
(but not /Wiki/Edit)
then pass all the rest of the URL as Id.
编辑:
嗯,只是另一个问题:
我怎样才能航线这一个:
http://en.wikipedia.org/wiki/C&A
维基百科可以...
编辑:
根据维基百科,由于与wiki文字语法冲突,只有下列字符永远无法在网页标题中使用(也不是由DISPLAYTITLE支持):
According to wikipedia, due to clashes with wikitext syntax, only the following characters can never be used in page titles (nor are they supported by DISPLAYTITLE):
# < > [ ] | { }
<一个href=\"http://en.wikipedia.org/wiki/Wikipedia:Naming_conventions_(technical_restrictions)#Forbidden_characters\">http://en.wikipedia.org/wiki/Wikipedia:Naming_conventions_(technical_restrictions)#Forbidden_characters
编辑:
为了让*和&安培;,把
To allow * and &, put
<httpRuntime requestPathInvalidCharacters="" />
成章节&lt;&的System.Web GT;在web.config中的文件
into section <system.web> in file web.config
(这里找到:<一href=\"http://www.christophercrooker.com/use-any-characters-you-want-in-your-urls-with-aspnet-4-and-iis\">http://www.christophercrooker.com/use-any-characters-you-want-in-your-urls-with-aspnet-4-and-iis)
推荐答案
您可以使用一个包罗万象的路线,以捕捉后面的维基链接到的
部分的一切 ID
标记:
You could use a catchall route to capture everything that follows the wiki
part of the url into the id
token:
routes.MapRoute(
"Wiki",
"wiki/{*id}",
new { controller = "Wiki", action = "DbLookup", id = UrlParameter.Optional }
);
现在,如果你有以下要求: /维基/ AS / 400
将映射到在维基以下动作
控制器:
Now if you have the following request: /wiki/AS/400
it will map to the following action on the Wiki
controller:
public ActionResult DbLookup(string id)
{
// id will equal AS/400 here
...
}
至于 /维基//
来讲我认为这个要求是以往任何时候都达到ASP.NET管道,你会从Web服务器400错误请求错误。您可以检出<一个href=\"http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx\">following博客文章。
As far as /wiki//
is concerned I believe you will get a 400 Bad Request error from the web server before this request ever reaches the ASP.NET pipeline. You may checkout the following blog post.
这篇关于在参数斜线的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!