Breaking my head to get Url Routing in IIS 7 hosting environment : ASP.NET Breaking my head to get Url Routing in IIS 7 hosting environment : ASP.NET asp.net asp.net

Breaking my head to get Url Routing in IIS 7 hosting environment : ASP.NET


I followed this article:How to: Use Routing with Web Forms

Before I found it I had issues on my shared host and none locally. It was my web.config.

My host was using IIS 7 with Integrated Pipeline, I was missing this:

<handlers>    <!---after all the others--->           <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*"             path="UrlRouting.axd"             type="System.Web.HttpForbiddenHandler,             System.Web, Version=2.0.0.0,             Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /></handlers>

EDIT: According to your settings and code, the only thing left is to check to see if you have the Routing dll defined in web.config and also deployed to your bin directory:

<add assembly="System.Web.Routing, Version=3.5.0.0,   Culture=neutral,   PublicKeyToken=31BF3856AD364E35"/>


Try this in you web.config. Worked for me.

<system.webServer>    <modules runAllManagedModulesForAllRequests="true" /></system.webServer>


Not sure if you were able to figure out what the problem was...however if you are still looking for a solution then you may try the following. I had to face the same situation some time back and got it to work using Rewrite rules in Web config for which you will not need any routing mechanism. So first I would encourage you to remove any routing setting you may have and the code from the Global.asax file too.

Then in the section you can add as rewrite rules as follows

<rewrite>    <rewriteMaps>        <rewriteMap name="map1" defaultValue="(.+)"/>    </rewriteMaps>    <rules>        <rule name="Rewrite rule1 for map1">        <match url="product/(.+)/(.+)"/>        <conditions>            <add input="{map1:{REQUEST_URI}}" pattern="(.+)"/>        </conditions>        <action type="Rewrite" url="productdetail.aspx?Product={R:1}" appendQueryString="false" redirectType="Permanent"/>        </rule>    </rules>  </rewrite>

If you have problems understanding the rewrite mechanism I would recommend that you read this article by Scott Guthrie.

I think this should work for you given a IIS 7.0 or 7.5 environment.