开发者

Getting 404 error on MVC web-site

开发者 https://www.devze.com 2023-02-12 15:39 出处:网络
I have an IIS7.5 web-site, on Windows Server 2008, with an ASP.NET MVC2 web-site deployed to it. The website was built in Visual Studio 2008, targeting .NET 3.5, and IIS 5.1 has been successfully conf

I have an IIS7.5 web-site, on Windows Server 2008, with an ASP.NET MVC2 web-site deployed to it. The website was built in Visual Studio 2008, targeting .NET 3.5, and IIS 5.1 has been successfully configured to run it as well, for local testing.

However, whenever I try and navigate to a page running in IIS7, I get a 404 error.

I have checked the following things:

  • There is no corresponding 404 log entry in IIS logs.
    • Actually, there are 404 entries in the IIS log.
  • The application开发者_如何学Python pool for the web-site is set to use the Integrated pipeline.
  • The "customErrors" mode is set to off.
  • .NET 3.5 SP1 is installed
  • ASP.NET MVC 2 is installed
  • I've used MVC Diagnostics to confirm all MVC DLLs are being found.
  • ASP.NET is enabled in IIS, which we've demonstrated by running the MVC Diagnostics page.
  • KB 2023146 did highlight that HTTP Redirection was off, so we've turned it on, but no joy.

EDIT Ok, so we've installed the world's simplest MVC application (the one which is created when you create a new MVC2 project in Visual Studio), and we are still getting 404s on any page we try and access - e.g. <my_server>/Home/About will generate a 404.

Any ideas will be greatly appreciated!


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.

Getting 404 error on MVC web-site


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!

Getting 404 error on MVC web-site


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:

Getting 404 error on MVC web-site


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消