1

I have the following routes in my ASP.NET MVC application:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
       name: "AppCode",
       url: "AppCode",
       defaults: new { controller = "AppToken", action = "AuthenticateUser", authCode = UrlParameter.Optional }
   );

    routes.MapRoute(
        name: "ReplayFileRoute",
        url: "Replays/{replayName}/{fileName}",
        defaults: new { controller = "Replay", action = "GetReplayFile" }
    );

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}

The problem is now that the following URL will cause a 404, and the "GetReplayFile"-Action not to be executed:

http://localhost:59174/Replays/kgm3eauw.zbg/raha5qit.ikp.pls

However, the following URL works:

http://localhost:59174/Replays/kgm3eauw.zbg/raha5qit.ikp.pls/

So when I add an tailing slash, ASP chooses the right route, else it does not. Adding a tailing slash isn't an option at this time, since the URLs will be generated by an external script. I do only pass

http://localhost:59174/Replays/kgm3eauw.zbg/

to the script, the actual file name will be generated by the script - without the tailing slash.

So my question is: How do I make the first URL to call the "right" method?

Also: Is there any documentation on how the RouteConfig exactly works? I haven't found much so far.

M. Schena
  • 2,039
  • 1
  • 21
  • 29
Flai
  • 160
  • 1
  • 8

1 Answers1

0

I guess the problem is that is expects your URL to point to a file and bypasses the ASP.NET MVC routing engine. You have to let all requests go through ASP.NET in order to let it match on URLs that look like a file too.

You can set this in your web.config file. Add this:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325