Thursday, August 4, 2016

Rewrite ASP.Net MVC homepage to another IP address

Leave a Comment

I have been trying to rewrite my homepage to another ip address in my ASP.Net MVC application. I have installed URL Rewrite and Application Request Routing modules in IIS. I have set the rewrite in my web.config, when i change the action type to redirect it works perfectly, but once i change it back to rewrite it does not work at all. I have changed the matching url to accept all requests, but still it does not work.

<system.webServer>         <rewrite>         <rules>         <clear />          <rule name="node" enabled="true" patternSyntax="Wildcard" stopProcessing="true">            <match url="*" />            <action type="Rewrite" url="http://255.255.255.255/" />          </rule>        </rules>      </rewrite>   </system.webServer> 

It seems like rewriting process has some conflicts with routing. How could i make the priority of rewrite higher?

3 Answers

Answers 1

Firstly you have to configure an Application Request Routing Server Farm that will consist of only one server (you should specify an IP for this server). After that you need to configure a global URL rewrite rule as described here.

Answers 2

The configuration of the URL Rewrite Module in the <rewrite> section is for internal URLs, and cannot rewrite domain or IP of the server:

IIS.NET: A Rewrite action replaces the current URL string with a substitution string. A substitution string must always specify the URL path (for example, contoso/test/default.aspx).

What you asked is not an url rewrite, but a reverse proxy. If you have an access to IIS, you can try its reverse proxy configuration, or simply create an HttpHandler, similar to this example. Next option can be http://urlrewriter.codeplex.com

Answers 3

Would there be config inheritance happening? If so, you can wrap the section you want with <location> to disable inheritence from parent app...

<location path="." inheritInChildApplications="false">   <system.webServer>     ...   </system.webServer> </location> 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment