2009-06-03 59 views
3

我发现ASP.Net mvc的路由机制的限制,我试图找到一种解决方法。扩展Asp.Net MVC路由机制

我张贴了关于我是有这个问题一个相关的问题here

问题的要点是,路由与一个结束。 (句点)从不由默认路由机制处理。总是抛出“无法找到资源”错误。例如,它不能处理这些URL:

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.如果有人可以请在这里提供一些帮助,我将不胜感激。

+0

尝试一下我自己,我看到时间顺利通过没有任何问题。你能发表一个你正在定义的路线和他们映射到的控制器的例子吗? – tghw 2009-06-03 17:33:49

+0

http://stackoverflow.com/questions/429963/the-resource-cannot-be-found-error-when-there-is-a-dot-at-the-end-of-the-url – GuyIncognito 2009-06-03 17:50:55

回答

1

你可以把检查文件的存在于路线,而是通过允许一定的扩展?

routes.RouteExistingFiles = true; 

// Ignore the assets directory which contains images, js, css & html 
routes.IgnoreRoute("Assets/{*pathInfo}"); 

// Ignore text, html, files. 
routes.IgnoreRoute("{file}.txt"); 
routes.IgnoreRoute("{file}.htm"); 
routes.IgnoreRoute("{file}.html"); 
routes.IgnoreRoute("{file}.aspx");