500 Internal Server Error after changing .NET Framework Version to 4.0 in IIS7

I just changed my .NET Framework Version of the Application Pools in IIS7 Manager, following Specify a .NET Framework Version for an Application Pool (IIS 7) instructions by Microsoft Technet. Now when I try to re-upload my ASP.NET page, it shows me a 500 - Internal server error. I have tried uploading it in .NET 2.0 (x86, x64, AnyCPU), and 4.0 (x86, x64, AnyCPU), and everything gives the same error. This is all the details the error gives me: "There is a problem with the resource you are looking for, and it cannot be displayed."

When keeping the .NET version 2.0 on the server, it works just fine. Also, when uploading index.htm, it works fine as well, it just shows the HTML page.

This is on Windows Server 2008 R2, by the way.

EDIT:

I have finally found out how to get the error details. Here they are:
Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list. Most likely causes:

  • Managed handler is used; however, ASP.NET is not installed or is not installed completely.
  • There is a typographical error in the configuration for the handler module list. Things you can try:
  • Install ASP.NET if you are using managed handler.
  • Ensure that the handler module's name is specified correctly. Module names are case-sensitive and use the format modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"

I am sure that I have installed ASP.NET completely.


Solution 1:

I found the solution. Apparently, it did not register my .NET 4.0 installation. I simply had to run this program with parameters: "C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i", and it fixed it!

Note that the path "C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe" may differ according to what version of the .NET framework is installed!
To see what path you need, open "C:\Windows\Microsoft.NET\Framework\", and see what the folders name is, and adjust it accordingly, like so: "C:\Windows\Microsoft.NET\Framework\<version>\aspnet_regiis.exe"

Solution 2:

There are specific command consoles for specific vs versions. So it avoids this headache of long paths as that is already set in the vs specific command console. Go to VS program directory and find the command console, and when it opens , just type in

aspnet_regiis.exe -i