Getting 404 error on MVC web-site

社会主义新天地 提交于 2019-11-27 22:59:10
Sam Shiles

This is quite often caused by the following missing from the web.config:

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

Do you have a problem with just 1 page or the whole site is not working?

A) 1 page

  • You can use RouteDebugger to verify if the route is matched correctly

B) Whole site

  • I assume you're using Windows Server - check if ASP.NET is enabled in IIS - it's disabled by default, I believe.

  • You can use MvcDiagnostics page to check if all dlls are deployed properly.

  • Are you running in IIS7 integrated mode? Classic mode of IIS7 does not automatically map extensionless URLs to ASP.NET (much like IIS6)

  • Make sure your Web.config tag is configured correctly.

We finally nailed this issue by exporting the IIS configuration of a working server, and comparing it to ours.

It was a really obscure setting which had been changed from the default.

IIS ROOT → request Filtering → Filename Extensions Tab → Edit Feature Settings → Allow unlisted file name extensions

This should be ticked.

This can be set at the IIS level, or the site-level.

Glad that fixed your problem. Others researching this issue should take note of the extensionless URL hotfix: http://support.microsoft.com/kb/980368

If none of the other solutions here solved your issue, check that you have the

Global.asax

file in your website. This solved the issue for me.

Checkout if KB 2023146 applies to your scenario. Also try requesting directly a controller action: /yoursitename/home/index

Apparently this can have many different causes.

For us, the problem was that the DNS entry was configured for two IP addresses, but the IIS configuration would only listen to one of them. So we got unpredictable results, sometimes it would work, sometimes a few files (css, etc) would not load, and sometimes the whole page would not load.

For me it was all about installing .NET Framework 4.6.1 on the server (my app was targeting that version)

You'll also get this if your bindings aren't correct. If you don't have www or a subdomain it'll return a 404.

I had this problem when running my MVC4 site with an app pool set to ASP.NET 4.0 and the Classic pipeline, even though the extension handlers were set in my web.config and were showing correctly in IIS. The site worked in Integrated Pipeline so I knew it was a configuration issue, but I couldn't nail it down. I finally found that ASP.NET 4 was disabled for the server in the ISAPI and CGI Restrictions settings. I enabled ASP.NET 4.0 and it worked.

In addition to checking if you're running in integrated pipeline mode, make sure your application pool is set to use .NET! I recently ran into this problem, and when I went in to check the app pool settings, I found that somehow it had been set to "No Managed Code." Whoops!

My Hosting company fixed this for me by doing this (I removed the original password value of course).

  <system.webServer>
    <security>
      <authentication>
        <anonymousAuthentication password="<password>" />
      </authentication>
    </security>
  </system.webServer>

Typically I encounter this issue when there is a Routing problem. I compare a working vs non-working to resolve it.


Today however I accidentially created a Virtual Directory in IIS.

It has to be an Application, right click on the Virtual Directory (with a folder icon) -> Convert to Application:

Don't use runAllManagedModulesForAllRequests. You want to let IIS handle resources such as images.

<system.webServer> <!-- Rather do NOT use this -->
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

Instead add the MVC routing module

<system.webServer>
  <modules>
    <remove name="UrlRoutingModule-4.0" />
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  </modules>
</system.webServer>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!