RB.
RB.

Reputation: 37172

Getting 404 error on MVC web-site

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:

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!

Upvotes: 13

Views: 55432

Answers (14)

Ananta R. Pant
Ananta R. Pant

Reputation: 106

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>

Upvotes: 0

Jeremy Thompson
Jeremy Thompson

Reputation: 65534

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:

enter image description here

Upvotes: 0

Rez.Net
Rez.Net

Reputation: 1462

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>

Upvotes: 0

Lanklaas
Lanklaas

Reputation: 2892

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.

Upvotes: 3

Michal B.
Michal B.

Reputation: 5719

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

Upvotes: 1

Sam Shiles
Sam Shiles

Reputation: 11249

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

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

Upvotes: 15

Mason G. Zhwiti
Mason G. Zhwiti

Reputation: 6530

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!

enter image description here

Upvotes: 0

Chris
Chris

Reputation: 2046

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.

Upvotes: 0

Kiki
Kiki

Reputation: 11

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.

Upvotes: 1

Andrew dh
Andrew dh

Reputation: 879

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.

Upvotes: 0

RB.
RB.

Reputation: 37172

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.

Screenshot of IIS showing location of Request Filtering option

Upvotes: 9

John Mathis
John Mathis

Reputation: 41

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

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

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

Upvotes: 2

Jakub Konecki
Jakub Konecki

Reputation: 46008

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.

Upvotes: 10

Related Questions