扩展 Asp.Net MVC 路由机制
我发现 ASP.Net mvc 的路由机制存在限制,我正在尝试找到解决方法。
我在此处发布了相关问题关于我遇到的问题。
问题的要点是以 . (句点)永远不会被默认路由机制处理。 总是抛出“找不到资源”错误。 例如,它无法处理这些网址:
http://www.wikipediamaze.com/wiki/Washington,_D.C.
http://www.wikipediamaze.com/wiki/anythingendinglikethis.
如果我将其更改为像这样的查询字符串参数,它可以正常工作:
http://www.wikipediamaze.com/wiki/?topic=Washington,_D.C.
我试图在路由机制中找到一个可扩展点,这将帮助我解决此问题。 我尝试过类似的其他解决方案:
//Global.asax.cs
protected void Application_Error()
{
var url = HttpContext.Current.Request.RawUrl;
if(TopicRegex.IsMatch(url))
{
var fixedUrl = FixUrlPath(url);
//This throws an error
Response.Redirect(fixedUrl);
//This also throws an error
Server.Transfer(fixedUrl );
}
}
我猜测 Response.Redirect 和 Server.Transfer 会抛出错误,因为在 MVC 中您应该从控制器调用 RedirectToAction 方法。 当然,我甚至无法到达控制器。
考虑到维基百科使用的 Apache 服务器可以很好地处理这个问题,这似乎是一个相当大的限制。 尝试一下http://en.wikipedia.org/wiki/Washington,_D.C. 如果有人可以在这里提供一些帮助,我将不胜感激。
I've found a limitation in the routing mechanism for ASP.Net mvc and I'm trying to find a workaround.
I posted a related question here about the issue I was having.
The gist of the problem is that routes that end with a . (period) are never handled by the default routing mechanism. A "Resource Cannot Be Found" error is always thrown. For example it cannot handle these urls:
http://www.wikipediamaze.com/wiki/Washington,_D.C.
http://www.wikipediamaze.com/wiki/anythingendinglikethis.
if I change it to querystring parameter like this it works fine:
http://www.wikipediamaze.com/wiki/?topic=Washington,_D.C.
I'm trying to find an extensibility point in the routing mechanism that will help me resolve this issue. I've tried other solutions like this:
//Global.asax.cs
protected void Application_Error()
{
var url = HttpContext.Current.Request.RawUrl;
if(TopicRegex.IsMatch(url))
{
var fixedUrl = FixUrlPath(url);
//This throws an error
Response.Redirect(fixedUrl);
//This also throws an error
Server.Transfer(fixedUrl );
}
}
I'm guessing that the Response.Redirect and Server.Transfer throw errors because in MVC you should be calling the RedirectToAction methods from the controller. Of course I can't even get to the controller.
This seems to be a pretty big limitation considering the Apache server that Wikipedia uses handles this just fine. try it out http://en.wikipedia.org/wiki/Washington,_D.C. If anyone could please offer some help here I would appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能否关闭检查路径中是否存在文件但允许某些扩展名通过?
Could you turn of checking file exists in the routes but allow certain extensions through?