ASP.NET 4.5 MVC 4 not working on Windows Server 2008 IIS 7

94,294

Solution 1

If you are not able to apply the QFE from kb 980368, instead of using the runAllManagedModulesForAllRequests solution as suggested in the accepted answer, you should use the modules configuration with preCondition="" shown below to avoid the negative impact on static content as described in the blog posts How asp.NET MVC Routing Works and its Impact on the Performance of Static Requests and Don't use runAllManagedModulesForAllRequests="true" when getting your MVC routing to work and some of the comments on the answers.

Scott Hanselman's blog post about runAllManagedModulesForAllRequests should add some weight to this argument. Rick Strahl's post Caveats with the runAllManagedModulesForAllRequests in IIS 7/8 is the best explanation of the interaction between the settings I have found. The IIS documentation on the module preCondition attribute is also worth a read.

Remember this configuration change is not necessary if you have applied the QFE as this behaviour becomes the default.

<system.webServer>
  <modules>
    <remove name="UrlRoutingModule-4.0" />
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  </modules>
</system.webServer>

Solution 2

Try using this:

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

EDIT:

The solution above will work for .NET 3.5 or below. If you are using .NET 4.0 or above, you might want to try installing IIS7 QFE

Also, this article is worth reading to understand the difference between those two.

Solution 3

I had a similar problem. I tried many of the solutions described here (the Web.Config system.webServer configuration entry, etc) to no avail. At the very end, I discovered what the issue was with my particular installation. I was publishing my website to the local file system and then copying those files onto the server. It turned out that the file Global.asax was not being part of the published files. Once I copied that file, the error went away.

Solution 4

As per https://stackoverflow.com/a/12521807/695829

I had the same issue and this hotfix fixed it: : http://support.microsoft.com/kb/980368

Solution 5

As mentioned by SonicTheLichen, if you are publishing from Visual studio, the gloabal.asax file is not copied by default. By copying the global.asax to your webserver should resolve the issue. Thanks SonicTheLichen for proving the solution.

Regards, Saurabh

Share:
94,294
Dominic St-Pierre
Author by

Dominic St-Pierre

Web developer / entrepreneur trying to become a better developer as much as possible.

Updated on July 09, 2022

Comments

  • Dominic St-Pierre
    Dominic St-Pierre almost 2 years

    Clearly I'm missing something, I'm unable to deploy a simple ASP.NET MVC 4, .NET 4.5 app on a Windows Small Business Server 2008 on IIS 7.

    .NET framework 4.5 is installed.

    Should I be supposed to see that version (4.5) on the Application Pool basic settings of the application? At this time, I only have 2.0 and 4.0, since 4.5 is like the 3.5 which only add on top of the 4.0 framework, I guess this is normal.

    When I browse the home page, I got the following error:

    403 - Forbidden: Access is denied. You do not have permission to view this directory or page using the credentials that you supplied.

    When I request the only controller named Page /page/index I get the 404 not found page. Like the ASP.NET process never get the http request.

    I can request a simple HTML page.

    The Application Pool is set to .NET 4.0 and Integrated as the Managed pipeline mode.

    NETWORK SERVICE has read/write access to the directory.

    The app work flawlessly from VS2012 of course.

    I'm clueless on what's not right here, and search engine queries are not helping much.

    Does anyone would have a hint, that would be extremely appreciated. Thanks

    Edit

    The dlls are already on the bin folder like System.Web.Mvc, System.Web.Razor etc.

    I created a empty test.aspx page to make sure asp.net worker process was getting the request, and yes the page was OK. So it appears that the MVC routing is not working, though I have ASP.NET MVC 3 web app working fine on that server.

    After the .NET 4.5 installation I did a aspnet_regiis -iru in case, that added an aspnet_client folder on the app, but still this does not fix the issue.

    Anonymous Authentication is Enable on IIS Authentication section, and Authorization show allow for all users.

    ASP.NET MVC 4 is installed, I just did a repair to make sure.

    Eventhough the ASP.NET MVC 4 is installed, the 404 error from requesting the /page/index action is returned by the standard IIS and not the standard aspnet error. So indeed it appears like the MVC 4 framework is not properly installed, by I just double check and do a repair. Where can I continue to investigate?

    @Mystere Man, I've changed the Anonymous Authentication to use the Application Pool identity, stop, start the app and still the same error. It really look like if ASP.NET MVC 4 is not taking the request.

    Here is a part of the web.config:

      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
      </system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
      </entityFramework>
    

    Edit 2012/09/27

    I've re-pair Microsoft Framework .NET 4.5 and repair the ASP.NET MVC 4, re-deploy the simple ASP.NET MVC 4 app, and I still get the same behaviour. I'm not sure what to do next, so I started a bounty in the hope that someone could help me find the problem.

    Edit 2014/01/31

    When I asked that question, I flagged the runAllManagedModulesForAllRequests as the accepted answer because it did solve the problem. But I was certainly not going to use this in production. I ask why I had to do this and did not have any answers.

    Than Martin Hollingsworth answer was really what I was looking for, a good way to fix this problem without all the performance issues related to the runAllManagedModulesForAllRequests.

    We almost gave up and bought a new Windows 2012 server (from which the ASP.NET MVC app work as is). After trying Martin's solution, the Windows 2008 server worked.

  • jan salawa
    jan salawa over 11 years
    Check EventViewer's application logs for an error. Check IIS logs from location C:\inetpub\logs for requests for a page. Next share these information here so will be easier to solve the problem.
  • Dominic St-Pierre
    Dominic St-Pierre over 11 years
    <modules runAllManagedModulesForAllRequests="true" /> this fix the problem, but why a out of the box web.config did not work as is. i.e. why am I forced to add this attribute, and is there any performance issue enabling this? Thanks
  • kdrvn
    kdrvn over 11 years
    This settings tells IIS to run managed modules for any requests, even for static requests (e.g.: images, .css, .js, ...), so it impacts the performances for those requests. You might want to read this article for more informations. The author of this article also provide another solution that you might want to try: installing IIS7 QFE.
  • Akash Kava
    Akash Kava about 11 years
    IIS7 QFE does not install for Windows 8, what to do now?
  • kdrvn
    kdrvn about 11 years
    Windows 8 runs IIS8, not IIS7. Take a look at this article.
  • JDwyer
    JDwyer almost 11 years
    We were running Windows Server 2008 with IIS 7 and .NET 4.5 adding <modules runAllManagedModulesForAllRequests="true" /> solved our problem. (So it's usefulness is not limited to 3.5 or below.)
  • xtravar
    xtravar over 10 years
    Jeez, it's a year later and it still took me four hours to find this solution. IIS is such a waste of time.
  • Dominic St-Pierre
    Dominic St-Pierre over 10 years
    Yes, this is the good way of fixing the issue, we bought a Win 2012 that worked fine, and I tried with your solution on the faulting Win 2008 and it work as expected. We are even going to keep the 2008 server now that it work without the runAllManageModulesForAllRequests.
  • uncoder
    uncoder almost 10 years
    Man, your answer deserves +1000, seriously! I spent half a day "troubleshooting" the broken routing, just to realize that I forgot to deploy Global.asax.
  • Admin
    Admin almost 10 years
    Glad to be of any help! :)
  • Jonas Kello
    Jonas Kello about 9 years
    If you have a Windows 2008 Server with IIS 7.0 (not R2) then this is the download link for the hotfix: microsoft.com/en-us/download/details.aspx?id=11342
  • Beweelam
    Beweelam almost 8 years
    Brilliant! Great success, very nice!