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

后端 未结 4 1959
灰色年华
灰色年华 2021-02-06 01:02

I am trying to implement ASP.NET URL routing using the System.Web.Routing. And this seems to work fine on my localhost however when I go live I am getting an II

相关标签:
4条回答
  • 2021-02-06 01:16

    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.

    0 讨论(0)
  • 2021-02-06 01:16

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

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
    
    0 讨论(0)
  • 2021-02-06 01:19

    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"/>
    
    0 讨论(0)
  • 2021-02-06 01:29

    Just to inform what was finally my solution... on the IIS7 change the pipeline mode to Integrated and I folowed adding some lines on the web.config from the link above... http://msdn.microsoft.com/en-us/library/cc668202.aspx

    good luck.

    0 讨论(0)
提交回复
热议问题