samedi 9 mai 2015

Change the URL root path in ASP.NET MVC or IIS

I'm working with a server with a custom URL: http://ift.tt/1AXJfnT and as you can see I need to change the default root path ("/") of my application to prevent 404 errors. Using IIS rewrite module with a outbound rule seems to work, with all html links and references being converted properly to query the internal website. The problem is when a Redirect() or RedirectToAction() method is used in my controllers, the internal name of the website is dropped so a 404 is caused. This is my IIS outbound rule:

<rewrite>
  <outboundRules>
    <rule name="Add path prefix to urls" stopProcessing="true">
      <match filterByTags="A, Form, Img, Link, Script" pattern="^/(.*)" />
      <action type="Rewrite" value="/site{R:0}" />
    </rule>
  </outboundRules>
</rewrite>

So to clarify: I have http://ift.tt/1AXJfnT when a redirection occurs to Account/Login, it becomes http://ift.tt/W9q91Q instead of http://ift.tt/1P7ZlIP . I guess the RouteConfig has to be tinkered with but I don't know how, or if I can do this in IIS. I have the following in my RouteConfig class:

routes.MapRoute(
    name: "SiteRoot",
    url: "site/{controller}/{action}",
    defaults: new { controller = "Home", action = "Index" }
);

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

Thank you.

Aucun commentaire:

Enregistrer un commentaire