1

I am new to ASP.NET MVC and when I tried to host my working application into IIS, the routing fails as I now requires the application name in front of my controller name.

Eg. my default page navigates using:

localhost/ControllerName/Index

However after hosting:

ipaddress/ApplicationName/ControllerName/Index

It now requires the ApplicationName before my controller.

I tried adding an additional MapRoute:

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

However it still navigates to the defaults.

How do I have the routing table skip the application name?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
LuxuryWaffles
  • 1,518
  • 4
  • 27
  • 50
  • 1
    I think (might be wrong though) that this is because your IIS can host multiple applications, so `ipaddress/ApplicationName` is so the IIS server knows which application you want to route to and has nothing to do with your actual application – MindSwipe Aug 05 '19 at 05:48
  • @MindSwipe Yes, it host multiple applications right now, will I have to manually change all the url? – LuxuryWaffles Aug 05 '19 at 05:58
  • No. If you change the routing (like you did in your example) the URL of the application will be `ipaddress/ApplicationName/ApplicationName/`. The `ipaddress/ApplicationName` routing scheme shouldn't be a problem, as long as you are generating your links (`foo` tags) and not hardcoding them. You can use [@Hmtl.ActionLink](https://stackoverflow.com/a/201341/9363973) to dynamically generate them – MindSwipe Aug 05 '19 at 06:36

0 Answers0