Search code examples
asp.netiisrazorhttp-status-code-404friendly-url

Fix Razor web pages with a friendly URL returning a 404 error


I have a website written in ASP.NET with Razor syntax in the file extension .cshtml. I wrote the site using WebMatrix and the site runs fine when I run it on web matrix's "LocalHost". The links and all my code work, but as soon as I try to run the website from my IIS server the page links no longer work properly.

When I click on a link it returns the 404 error page. If I type in the .cshtml extension the page loads correctly and all is right with the world except the file extension. The only page that still works is the index page because it is a default page.

Every place I've checked says that it should run without the extension as a default of ASP.NET or if it doesn't run as default then use the URL re-write plugin.

The Default isn't running and I am unable to use the URL rewrite tool.

What can I do to get the default to work, or is there another way to have the extensions not display without using URL re-write?

I know that if I put the files in a folder with the link name and rename them to index.cshtml this will work, but I feel it is a very backhanded way of doing it so I would prefer not to do it that way.

Before any one suggests a solution for MVC I am explicitly NOT USING MVC Logic.


Solution

  • Try two things:

    1. Set the application pool to ASP.NET 4.0. Then restart IIS.

    2. Add the following key to <system.webServer> section of Web.Config:

      <modules runAllManagedModulesForAllRequests="true" />