Asp.net-mvc – ASP MVC routing problem with IIS7

asp.netasp.net-mvc

We discovered problem when deploying MVC application on IIS7 server: any route navigation gives 404 error. I've found on web that problem can be solved by setting application pool managed pipeline mode to integrated, but now we have exception:

Request is not available in this context

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Request is not available in this context

Source Error: 


Line 19: 
Line 20:         public override void SetActiveUser(Guid userOid) {
Line 21:             FormsAuthentication.SignOut();
Line 22:             HttpContext.Current.Items[Key] = userOid.ToString();
Line 23:             FormsAuthentication.RedirectFromLoginPage(userOid.ToString(), true); 

Does anybody have any ideas?

Best Answer

The problem is probably in the web.config file. Since IIS7 there is now two places to configure handlers and modules. When you run in classic mode, is like running on IIS 6 (though under IIS7).

Here is the config file:

<system.web>
[...]
    <httpHandlers>
            [...]
        </httpHandlers>
        <httpModules>
            [...]
            <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

        </httpModules>
    </system.web>

there should be only IIS 6 configurations.

IIS 7 config should be placed under:

    <system.webServer>
[...]
            <modules runAllManagedModulesForAllRequests="true" >
                <remove name="UrlRoutingModule"/>
                <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            </modules>
            <handlers>
                <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>
        </system.webServer>