Rectangle 27 26

"HTTP Errors" and "HTTP Redirection" services must be added to the "Web Server (IIS)" role in the "Server Manager" control panel. If you want to get static content like CSS and Javascript working, too, enable "Static Content" service as well.

An oldie but a goody. Spot on.

If this helps (it did for me :)), maybe you could accept the answer?

I was about to pull my hair out on a published MVC app proven to work in another IIS 7 instance that was just returning a blank page but the code was running in this second IIS 7 instance on Windows Server 2008 R2. Finally after adding these Service Roles, success. Thanks!

iis 7 - ASP.net MVC on IIS 7 returning blank page - Stack Overflow

asp.net-mvc iis-7
Rectangle 27 1

Just thought I'd add another reason why IIS / MVC might return a blank page... suppose you've got an app pool identity, which is authorised against the SQL database. Now suppose you've got two different identities, one for production, and one for pre-production. Now, further suppose that one of your esteemed colleagues decides to restore the database from production, over the one that exists in pre-production. Now you've got a copy of the prod database in pre-prod, which is authorised for the production user, but not for the pre-production user. In that situation, I was getting blank pages in pre-production now, because the authorisation for the pre-production user (which previously existed in the pre-production database) has now been wiped out by the restore of the database. Because that user ID is the app pool identity, now your MVC app no longer has rights to the database. This caused MVC to render blank pages, and caused me two days of chasing my tail because I thought someone had changed some IIS setting on the web server, but it was actually a database permissions issue. Maybe this will give a clue to someone with a similar problem in the future.

I think I'm getting the same problem, but don't know how to be sure. How did you discover that the problem is because of the DB but not IIS?

It's been a while since I worked on that, but I believe it's because I tried to log directly into the database using that user ID, (via SQL login), and discovered I could not log in, so that was a clue that user no longer existed!

Thanks David. My issue is different, but it also gets a lot more difficult than it should be if there's more accurate error report. The error message returned should be clearer.

iis 7 - ASP.net MVC on IIS 7 returning blank page - Stack Overflow

asp.net-mvc iis-7
Rectangle 27 27

Are you running in IIS7 integrated mode?

Classic mode of IIS7 does not automatically map extensionless URLs to ASP.NET (much like IIS6).

Also make sure your Web.config <system.webServer> tag is configured correctly.

Diagnosing 404 errors on IIS 7 and ASP.NET MVC - Stack Overflow

asp.net asp.net-mvc iis iis-7 httphandler
Rectangle 27 27

Are you running in IIS7 integrated mode?

Classic mode of IIS7 does not automatically map extensionless URLs to ASP.NET (much like IIS6).

Also make sure your Web.config <system.webServer> tag is configured correctly.

Diagnosing 404 errors on IIS 7 and ASP.NET MVC - Stack Overflow

asp.net asp.net-mvc iis iis-7 httphandler
Rectangle 27 22

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

This answer also worked and does appear to have a more efficient (and elegant) approach.

This method worked well for me in an ASP.NET Web API application. The app worked fined locally, but when deployed to any other environment, I just received a 404 for any Web API request. Added the routing module bits noted above and everything is fine. Similar issue here: stackoverflow.com/questions/15389855/. Thanks!

I was pulling my hair out trying to get an MVC app to accept HTTP DELETE requests. This took care of it for me. Thanks!

same problem, the method delete request don't work if i deploy to other environment: iis 8 ok but in other environment (iis 7) i get 404

Diagnosing 404 errors on IIS 7 and ASP.NET MVC - Stack Overflow

asp.net asp.net-mvc iis iis-7 httphandler
Rectangle 27 22

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

This answer also worked and does appear to have a more efficient (and elegant) approach.

This method worked well for me in an ASP.NET Web API application. The app worked fined locally, but when deployed to any other environment, I just received a 404 for any Web API request. Added the routing module bits noted above and everything is fine. Similar issue here: stackoverflow.com/questions/15389855/. Thanks!

I was pulling my hair out trying to get an MVC app to accept HTTP DELETE requests. This took care of it for me. Thanks!

same problem, the method delete request don't work if i deploy to other environment: iis 8 ok but in other environment (iis 7) i get 404

Diagnosing 404 errors on IIS 7 and ASP.NET MVC - Stack Overflow

asp.net asp.net-mvc iis iis-7 httphandler
Rectangle 27 27

I found the solution. You have to add and remove the SessionStateModule:

<configuration>
  ...
  <system.webServer>
    ...
    <modules>
      <remove name="Session" />
      <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
      ...
    </modules>
  </system.webServer>
</configuration>

I have no idea why Microsoft doesn't add this to the web.config of the project template?

Never saw this need to remove and add. Might be some particularity of MVC4 + IIS7... It worked for me! +1

iis 7 - The Session object is null in ASP.NET MVC 4 webapplication onc...

asp.net-mvc-4 iis-7
Rectangle 27 27

I found the solution. You have to add and remove the SessionStateModule:

<configuration>
  ...
  <system.webServer>
    ...
    <modules>
      <remove name="Session" />
      <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
      ...
    </modules>
  </system.webServer>
</configuration>

I have no idea why Microsoft doesn't add this to the web.config of the project template?

Never saw this need to remove and add. Might be some particularity of MVC4 + IIS7... It worked for me! +1

iis 7 - The Session object is null in ASP.NET MVC 4 webapplication onc...

asp.net-mvc-4 iis-7
Rectangle 27 3

I have a number of asp.net(not MVC) sites successfully running on this machine. The message suggests to me it is originating from the routing feature.

Copy n paste the error messages online so we can see them to help u find an answer

iis 7 - ASP.NET MVC running IIS7 deployment problem - Stack Overflow

asp.net-mvc iis-7
Rectangle 27 12

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

Wow this actually worked! But why do I have the feeling it will come back to haunt me?

Diagnosing 404 errors on IIS 7 and ASP.NET MVC - Stack Overflow

asp.net asp.net-mvc iis iis-7 httphandler
Rectangle 27 12

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

Wow this actually worked! But why do I have the feeling it will come back to haunt me?

Diagnosing 404 errors on IIS 7 and ASP.NET MVC - Stack Overflow

asp.net asp.net-mvc iis iis-7 httphandler
Rectangle 27 35

You actually just reminded me that I needed to fix this issue in an enviroment here. If your situation is the same as mine then it's a simple fix.

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

Edit: To provide further explanation on the issue at hand. In my case what was happening was when I added custom route mappings IIS was seeing the requests as Folder/Static File requests and thus was skipping over the ASP.NET worker process. This behaves differently under development environment generally because it is being run under the development web server which will also pass all requests through the .net process.

This Web Config entry tells IIS that you have modules that should be run on every web request even if IIS determines it to be a static file or a folder.

As an aside, if your webservices are in the same web container as your aspx files you will hit a snag because the native modules will not be run and static files (like images) will not be properly served. Putting the webservices elsewhere will probably (hopfully mitigate).

Had the same issue going from dev environment on win7 to win2k8 live server. Project mixes webforms with mvc3. Solved my problem.

I spent an hour on this before I came across this answer and it worked! Why do we need this? and why isn't it in by default if we do?

I added an update to my original answer with some further explanation into why it's needed. Why it's not included is that it's normal behavior in IIS to not run static files through the worker process.

iis 7 - Getting 404.0 error for ASP.NET MVC 3 app on IIS 7.0 / Windows...

iis-7 .net-4.0 asp.net-mvc-3 windows-server-2008 asp.net-4.0
Rectangle 27 1

Is IIS in Integrated Mode? If it's not, you'll have to do some setup or change it to Integration Mode

iis 7 - ASP.NET MVC running IIS7 deployment problem - Stack Overflow

asp.net-mvc iis-7
Rectangle 27 1

Please make sure that you are running under IIS 7.0 Integrated mode. If you need to run it under IIS 7.0 Classic mode, you need to perform several actions to make the routes work. Please refer the following blog posts;

Thanks that helped me out (I'm having to work with IIS7 in Classic mode)

@codeulike u're welcome. happy that helps.

iis 7 - ASP.NET MVC running IIS7 deployment problem - Stack Overflow

asp.net-mvc iis-7
Rectangle 27 5

Is IIS configured to server .svc files? You may need to add the .svc MIME type to IIS

  • Click on 'Add' to add the .svc MIME type

The problem you're running into is due to a build provider that is registered for .svc files. This build provider is registered by the default machine level web.config file.

<system.web>
  <compilation debug="true" targetFramework="4.0">
    <buildProviders>
        <remove extension=".svc"/>            
    </buildProviders>

Tried that - it doesn't have any effect - Also if I use an unknown extension (like .bob) it works fine.

Ok, this can be replicated in a the default new application template, so I had a quick look around and found some more information. I've updated my answer.

The build provider thing did it.

iis 7 - ASP.Net MVC 404 errors when route contains an .svc extension -...

asp.net-mvc iis-7
Rectangle 27 19

Is it possible to run an MVC application from a virtual directory in IIS7?

Not only that it is possible but it is the preferred way.

Which kind of messes things up for routing.

Not if you use Html helpers when dealing with urls which will take care of this.

Here's a typical example of what you should never do:

<script type="text/javascript">
    $.ajax({
        url: '@Url.Action("index", "home")'
    });
</script>

Here's another typical example of something that you should never do:

<a href="/home/index">Foo</a>
@Html.ActionLink("Foo", "Index", "Home")

Here's another example of something that you should never do:

<form action="/home/index" method="opst">

</form>

and here's how this should be written:

@using (Html.BeginForm("Index", "Home"))
{

}

just curious: why is it the preferred way?

@M4N, because every ASP.NET application (no matter whether it is MVC or not) must reside in a virtual directory. If you deploy it at the site root, this site root still represents a virtual directory.

What do I call from within a class (not a controller class or view) to get the path to say, /home/index?

Because as developers we should be using REAL tools, the same tools we'd be using on a dev, staging, or production server. Why would anyone want to use some stupid shit cassini...it causes issues which i don't need to go into details why...look it up. Why NOT use IIS should be the question. The Dev community is a bunch of lazy asses who don't want to learn how to do their job...part of that is learning IIS, so you can learn about how app pools work, page handlers, and so much more. Get in the ballgame, stop using shitty cassini. THAT'S WHY.

iis 7 - Running an ASP.NET MVC app from a virtual directory in IIS7 - ...

asp.net-mvc-3 iis-7
Rectangle 27 1

If you have a path leading to an eventual [Authorize] attribute, that will cause this - removing the RenderAction or allowing that action to render without [Authorize] fixes it.

In my case, I call Html.RenderAction("Heading") in _Layout.cshtml (renders a "Please log in" or "Welcome back, Ryan"). My Heading actionresult had an AuthorizeAttribute set on it. I removed the AuthorizeAttribute on Heading, and it was resolved.

Couple of hours digging in IIS config and the problem was in my app. Thank you for the hint. The issue is that in dev this kind of problems never show up unless you use IIS express.

iis 7 - ASP.NET MVC Deploying an app with forms authentication to IIS ...

asp.net-mvc iis-7 forms-authentication
Rectangle 27 14

In the Global.asax.cs file add the following route entry:

routes.IgnoreRoute("Shop/{*pathInfo}");

It appears that the MVC routing system kicks in before ARR, which makes sense when running in integrated mode.

This is definitely the answer. Be sure to rebuild your app after implementing if it's not working. edit: SLaks is probably right about the order, but this gets it working.

iis 7 - Using IIS Application Request Routing (ARR) for ASP.NET MVC - ...

asp.net-mvc iis-7 asp.net-mvc-routing
Rectangle 27 438

Chances are you need to install .NET 4 (Which will also create a new AppPool for you)

First make sure you have IIS installed then perform the following steps:

cmd
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\
aspnet_regiis.exe -ir
  • If this is a fresh version of IIS (no other sites running on it) or you're not worried about the hosted sites breaking with a framework change you can use -i instead of -ir. This will change their AppPools for you and steps 5-on shouldn't be necessary.
  • Close the DOS prompt, re-open your start menu and right click Computer and select Manage
  • You'll now have a new applet within the content window exclusively for IIS.
  • Expand out your computer and locate the Application Pools node, and select it. (You should now see ASP.NET v4.0 listed)
  • Expand out your Sites node and locate the site you want to modify (select it)
  • To the right you'll notice Basic Settings... just below the Edit Site text. Click this, and a new window should appear
  • Select the .NET 4 AppPool using the Select... button and click ok.
  • Restart the site, and you should be good-to-go.

(You can repeat steps 7-on for every site you want to apply .NET 4 on as well).

  • .NET 4 Framework The framework for those that don't already have it.
-i
-ir

Just make sure to run the cmd prompt with Administrative rights

Thanks for this - setup a new web server installed everything from web PI, latest framework updates and what do you know? IIS isn't even aware of ASP.NET ... this has happened too many times before, Microsoft, you really need to great rid of the clowns responsible for this.

@Brad I didn't get a new app pool. The log file from running regiis, shows .NET 4 was successfully installed, and now I can select .NET 4 as the "ASP.NET version" for a site. But it seems I still have to manually create a new app pool(since I can't mix v2 apps with v4 apps in the same pool).

Yes, correct. The App Pools node doesn't have anything new, and from the site there is no new pool to select. I can select .NET 4 as the "ASP.NET Version", but if it is in the default app pool with the .NET 2 apps, then it won't run and Event Log shows the error about different .NET versions running in the same app pool. This is IIS 6 if that is relevant. So I manually created a new app pool to put my new .NET 4 application in.

How to add ASP.NET 4.0 as Application Pool on IIS 7, Windows 7 - Stack...

asp.net iis
Rectangle 27 438

Chances are you need to install .NET 4 (Which will also create a new AppPool for you)

First make sure you have IIS installed then perform the following steps:

cmd
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\
aspnet_regiis.exe -ir
  • If this is a fresh version of IIS (no other sites running on it) or you're not worried about the hosted sites breaking with a framework change you can use -i instead of -ir. This will change their AppPools for you and steps 5-on shouldn't be necessary.
  • Close the DOS prompt, re-open your start menu and right click Computer and select Manage
  • You'll now have a new applet within the content window exclusively for IIS.
  • Expand out your computer and locate the Application Pools node, and select it. (You should now see ASP.NET v4.0 listed)
  • Expand out your Sites node and locate the site you want to modify (select it)
  • To the right you'll notice Basic Settings... just below the Edit Site text. Click this, and a new window should appear
  • Select the .NET 4 AppPool using the Select... button and click ok.
  • Restart the site, and you should be good-to-go.

(You can repeat steps 7-on for every site you want to apply .NET 4 on as well).

  • .NET 4 Framework The framework for those that don't already have it.
-i
-ir

Just make sure to run the cmd prompt with Administrative rights

Thanks for this - setup a new web server installed everything from web PI, latest framework updates and what do you know? IIS isn't even aware of ASP.NET ... this has happened too many times before, Microsoft, you really need to great rid of the clowns responsible for this.

@Brad I didn't get a new app pool. The log file from running regiis, shows .NET 4 was successfully installed, and now I can select .NET 4 as the "ASP.NET version" for a site. But it seems I still have to manually create a new app pool(since I can't mix v2 apps with v4 apps in the same pool).

Yes, correct. The App Pools node doesn't have anything new, and from the site there is no new pool to select. I can select .NET 4 as the "ASP.NET Version", but if it is in the default app pool with the .NET 2 apps, then it won't run and Event Log shows the error about different .NET versions running in the same app pool. This is IIS 6 if that is relevant. So I manually created a new app pool to put my new .NET 4 application in.

How to add ASP.NET 4.0 as Application Pool on IIS 7, Windows 7 - Stack...

asp.net iis