I'm working with a server with a custom URL: http://example.com/site/ 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://example.com/site/ when a redirection occurs to Account/Login, it becomes http://example.com/account/login instead of http://example.com/site/account/login . 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.