3

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.

Community
  • 1
  • 1
Micah
  • 111,873
  • 86
  • 233
  • 325
  • Trying it out myself, I'm seeing periods being passed in without any problem. Could you post an example of the routes you're defining and the controllers they map to? – tghw Jun 03 '09 at 17:33
  • http://stackoverflow.com/questions/429963/the-resource-cannot-be-found-error-when-there-is-a-dot-at-the-end-of-the-url – GuyIncognito Jun 03 '09 at 17:50

1 Answers1

1

Could you turn of checking file exists in the routes but allow certain extensions through?

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");
TWith2Sugars
  • 3,384
  • 2
  • 26
  • 43