Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run Simple ASP.NET MVC Application with Visual Studio 2015 from IIS (Internal Server 500)

  • Windows 10 Professional
  • IIS 10
  • Visual Studio 2015 (Running as Administrator)

I want to run from IIS instead of IIS Express as I have an external IP pointing to my machine and I will be receiving messages from an external source. Ultimately I will be using WebAPI but for testing and setting up IIS I am using a simple ASP.NET MVC 5 Web Application.

I created a new ASP.NET MVC 5 Web Application, this is the skeleton Visual Studio 2015 MVC Template, I then ran the application using IIS Express, no issues:

enter image description here

I then went to IIS 10 and created a new website with "localhost" as the binding:

enter image description here

The Physical Path for this new website in IIS is C:\inetpub\wwwroot\AspNetMvcTest:

enter image description here

I then went to the web application properties and switched to IIS. I was asked if I would like to create a new Virtual Directory:

enter image description here

I clicked Yes, if you click No the operation will be canceled and you unsaved Web Application Properties. You have to click Yes to change to Local IIS Property in Visual Studio.

I then was told that IIS "localhost" was mapped to a different folder and would I like to remap:

enter image description here

I clicked Yes. If you click No you will have unsaved Web Application Property changes again and you will not be using Local IIS in Visual Studio.

This is interesting Visual Studio is trying to change the "Virtual Directory" because it will actual change the Physical Path of the IIS Website not add a Virtual Directory. A Virtual Directory is a folder, somewhere outside of the Physical Path of the IIS website that IIS will treat as is part of the Physical Path folder. But I digress.

Now I am told that the "Virtual Directory" was created successfully:

enter image description here

Now we can look at the changes Visual Studio 2015 made to IIS 10:

We have no Virtual Directories on the website bound to localhost:

enter image description here

My Physical Path has been changed by Visual Studio 2015 and it is mapped to my the directory my simple ASP.NET MVC 5 Web Application resides:

enter image description here

So even though Visual Studio 2015 uses the "Virtual Directory" when changing the ASP.NET MVC 5 Web Application Properties, Visual Studio 2015 was only concerned with the Physical Path and that is the only thing it changed in IIS that I can see.

Now for the Internal Server Error 500 Details

I press F5 in Visual Studio 2015 and F12 Tools says there is an Internal Server 500 Error:

enter image description here

If we inspect the request and response in Fiddler, there 500 Error has a Content Length = 0

enter image description here

To try and get more details of the 500 error I have turned Custom Errors off in my Web.Config and also added httpErrors Detailed and PassThrough:

enter image description here

I added "catch all" exceptions handling to Global.asax, no breakpoint hitenter image description here:

Here is my Call Stack, which is empty and neither breakpoint in screenshot is ever hit:

enter image description here

I added a Console Application to my solution as "Set As Startup Project" and here is my Call Stack proving a break point can be hit:

enter image description here

Here is a screenshot of Event Viewer -> Application, I cleared the Application log, pressed F5 in Visual Studio 2015, refreshed the Application log and it is empty still:

enter image description here

I thought the issue is folder permissions after Visual Studio changed the Physical Path

So I added IIS_IUSRS and gave Full Control even though the Account does not need that high of a level of permission to the Physical Path directory:

enter image description here

My ApplicationPoolIndentity is Framework v4.0 and ApplicationPoolIdentity The ApplicationPoolIdentity is assigned membership of the Users group as well as the IIS_IUSRS group:

enter image description here

I tried adding the specific Application Pool to the Security properties of ASP.NET MVC app Physical Directory, so first I found the process Visual Studio F5 was attached to:

enter image description here

I added "DefaultAppPool" and my IIS Application Pool "IIS APPPOOL\AspNetMvcTest" to the Physical folder Security.

I added index.html to the Web Application Physical Folder and that does not work:

<html>
<head>
</head>
<body>
<h4 style="color: black">hello world</h4>
</body>
</html>

I have moved the IIS website Physical Path to inetpub/wwwroot back to the directory I created when I created the website, I cannot even browse to a simple HTML file, I get the same empty 500 error

enter image description here

So now I am stuck and do not know what else to do.

like image 687
Brian Ogden Avatar asked Feb 12 '16 18:02

Brian Ogden


1 Answers

TL;DR

Before reading the rest of answer it is likely you just need to run aspnet_regiis which you can do from cmd or via a cool tool in Web Platform Installer, if you search "ASP.NET" there is a handy "Execute ASP.NET IIS Registration tool" you can install.

Original Answer:

Thanks for all the help from everyone, first thing I should have done was taken a step back and tested an index.html "Hello World" test file from a IIS Website with c:\inetpub\wwwroot as the Physical Path of the IIS website.

When you first install IIS you have a default website, browse to it and make sure that works. Is a great first start to a new machine. But I just deleted that IIS site after installing IIS

Steps I took for fix:

  1. I uninstalled IIS via Control Panel -> Programs and Features -> Windows Features.
  2. Restarted my computer
  3. Installed IIS for Windows 10 following this document
  4. Tested IIS by creating a Website, using the DefaultAppPool and then browsing localhost, and that worked (again when you first install IIS you have this website but I deleted it on mine a couple days ago)
  5. I Found that my simple ASP.NET Website still did not work though and it was published to c:\inetpub\wwwroot\AspNetMvcTest so it was not a potential folders permission issue. When browsing, instead of loading my ASP.NET Website IIS redirected to the root c:\inetpub\wwwroot and displayed its IIS Welcome page ("iisstart.htm")
  6. This means I needed to run aspnet_regiis, which I did, via cool tool in Web Platform Installer, if you search "ASP.NET" there is a handy "Execute ASP.NET IIS Registration tool" you can install.
  7. That was it, I was all set, ASP.NET MVC Website started working from IIS immediately upon refreshing my browser (localhost in Location bar).

enter image description here

like image 149
Brian Ogden Avatar answered Sep 22 '22 07:09

Brian Ogden