MapRoute index.asp not routing to controller

117 Views Asked by At

I have the following MapRoute which works and routes to the controller 'Hotel'

 routes.MapRoute("Hotel", "en/hotels/london/victoria/my_hotel_name/", 
            new { controller = "Hotel", action = "Index" }, namespaces: new[] { "UrlRouter.Router.Controllers" } );

However, if the user enters filename index.asp in the path it doesn't route to the controller and just loads the actual content in the .ASP file, which is what I don't want. I want it to route to the controller, so I can control what is returned to the user.

The route I tried was

routes.MapRoute("Hotel", "en/hotels/london/victoria/my_hotel_name/index.asp", 
            new { controller = "Hotel", action = "Index" }, namespaces: new[] { "UrlRouter.Router.Controllers" } );
1

There are 1 best solutions below

0
neildt On BEST ANSWER

After further investigation, I found the following works. Add in web.config

 <modules>
  <remove name="UrlRoutingModule-4.0" />
  <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />

Then in Register routes

    public static void RegisterRoutes(RouteCollection routes)
    {

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.RouteExistingFiles = true;

        routes.MapRoute("Hotel", "en/hotels/london/victoria/my_hotel_name/{*.*}",
            new { controller = "Hotel", action = "Index", }, namespaces: new[] { "UrlRouter.Router.Controllers" });
     }

This allows me to route both these URLs to my Hotel controller and return a MVC view

www.mydomain.com/en/hotels/london/victoria/my_hotel_name/

and

www.mydomain.com/en/hotels/london/victoria/my_hotel_name/index.asp

If anyone has a better suggestion please post your answer.