62

I've installed website on my local machine using IIS 7 successfully. But when I've deployed it on live server, I got the following error:

"The page cannot be displayed because an internal server error has occurred" Nothing else.

Using the same IIS 7 on live and also set to have Detailed errors in Error Pages module, but still getting the same. What can be a reason?

Thanks

Spider man
  • 3,224
  • 4
  • 30
  • 42
progproger
  • 958
  • 2
  • 10
  • 21

10 Answers10

89

I just got this error and it was caused by a duplicate static content MIME type in the web.config

This error was being returned only on static files - eg images, css, js files were all saying this error (text by itself, no other html or text in the response).

The way to debug this is to look in web config under static content. Here we have a json file extension loaded. This was required on IIS7 but will kill the app if used on IIS8 because json is now pre-loaded at the server level.

    <staticContent>
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
        <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>

So solution is to remove any of these mimeType entries one at a time to confirm which are needed and which kill your app!

Update

Actually the best solution was provided by a commenter here. You can remove and then add, which will always work regardless of whether it is already defined or not. Like this:

<remove fileExtension=".json" /> 
<mimeMap fileExtension=".json" mimeType="application/json" />
mike nelson
  • 21,218
  • 14
  • 66
  • 75
  • 11
    It also applies to types such as .woff. – smoksnes Apr 01 '16 at 05:31
  • I was sure this one didn't apply to me, but I removed everything in staticContent and I can finally see the real error message! Thanks. – MGOwen Nov 05 '16 at 11:16
  • 3
    Clearing the entry before setting it should prevent clashes – zeristor Mar 29 '17 at 14:47
  • 1
    This is exactly the issue i had... Removing as above did the trick, thanks! – Andrew Stalker Apr 20 '18 at 15:59
  • same here, the MIME types in the web.config file for MVC app were already defined in the server IIS applicationConfig file, so once removed from the web.config file at the site level, statis files were served. – TamerDev Feb 14 '20 at 17:48
47

I think the best first approach is to make sure to turn on detailed error messages via your web.config file, like this:

<configuration>
    <system.webServer>
        <httpErrors errorMode="Detailed"></httpErrors>
    </system.webServer>
</configuration>

After doing this, you should get a more detailed error message from the server.

In my particular case, the more detailed error pointed out that my <defaultDocument> section of the web.config file was not allowed at the folder level where I'd placed my web.config. It said

This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false". "

bdukes
  • 152,002
  • 23
  • 148
  • 175
Eric Barr
  • 3,999
  • 5
  • 29
  • 42
8

Modify your web.config to display the server error details:

<system.web>
  <customErrors mode="Off" />
</system.web>

You may also need to remove/comment out the follow httpErrors section

  <system.webServer>
    <httpErrors errorMode="Custom">
      <remove statusCode="404" />
      <error statusCode="404" path="/Error/Error404" responseMode="ExecuteURL" />
      <remove statusCode="500" />
      <error statusCode="500" path="/Error/Error500" responseMode="ExecuteURL" />
      <remove statusCode="403" />
      <error statusCode="403" path="/Error/Error403" responseMode="ExecuteURL" />
    </httpErrors>
  </system.webServer>

From my experience if you directly have a server error, this may be caused from an assembly version mismatch.

Check what is declared in the web.config and the actual ddl in the bin folder's project.

Matthew Lock
  • 13,144
  • 12
  • 92
  • 130
Mickael LY
  • 184
  • 5
  • In my case, I was migrating a web site from II7 to an IIS8.x Win 2012 Server, and it seems the format for httpErrors may be slightly different between the two servers. Commenting out the httpErrors section fixed the issue for me. I recreated the custom errors from the IIS8.5 GUI after deleting the httpErrors section from the web.config that came from the IIS7.x server. – AdamantineWolverine May 21 '19 at 09:02
5

I've fixed it. I had the following section in web.config :

httpErrors existingResponse="PassThrough"

When I remove it, I got a real error

Divyang Desai
  • 7,483
  • 13
  • 50
  • 76
progproger
  • 958
  • 2
  • 10
  • 21
3

In my case, setting httpErrors and the like in Web.config did not help to identify the issue.

Instead I did:

  1. Activate "Failed Request Tracing" for the website with the error.
  2. Configured a trace for HTTP errors 350-999 (just in case), although I suspected 500.
  3. Called the erroneous URL again.
  4. Watched in the log folder ("%SystemDrive%\inetpub\logs\FailedReqLogFiles" in my case).
  5. Opened one of the XML files in Internet Explorer.

I then saw an entry with a detailed exception information. In my case it was

\?\C:\Websites\example.com\www\web.config ( 592) :Cannot add duplicate collection entry of type 'mimeMap' with unique key attribute 'fileExtension' set to '.json'

I now was able to resolve it and fix the error. After that I deactivated "Failed Request Tracing" again.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
1

it seems it works after I commented this line in web.config

<compilation debug="true" targetFramework="4.5.2" />
Sulyman
  • 440
  • 5
  • 14
  • In this case, I believe you could simply install that framework version (or maybe a higher one) from Windows "Programs and Features", under the IIS section. – NoOne Jun 10 '19 at 19:18
1

I ended up on this page running Web Apps on Azure.

The page cannot be displayed because an internal server error has occurred.

We ran into this problem because we applicationInitialization in the web.config

<applicationInitialization
    doAppInitAfterRestart="true"
    skipManagedModules="true">
    <add initializationPage="/default.aspx" hostName="myhost"/>
</applicationInitialization>

If running on Azure, have a look at site slots. You should warm up the pages on a staging slot before swapping it to the production slot.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Vishal
  • 595
  • 7
  • 12
1

I got the same error when I added the applicationinitialization module with lots of initializationpages and deployed it on Azure app. The issue turned out to be duplicate entries in my applicationinitialization module. I din't see any errors in the logs so it was hard to troubleshoot. Below is an example of the error code:

  <configuration>
  <system.webServer>
    <applicationInitialization doAppInitAfterRestart="true" skipManagedModules="true">
      <add initializationPage="/init1.aspx?call=2"/>
      <add initializationPage="/init1.aspx?call=2" />
    </applicationInitialization>
  </system.webServer>

Make sure there are no duplicate entries because those will be treated as duplicate keys which are not allowed and will result in "Cannot add duplicate collection entry" error for web.config.

Fahad
  • 41
  • 6
1

I was hosting with Everleap and migrated to Azure, where I was getting this error. Everleap deployments to their servers required the following in the web.config `<system.webServer> section:

<modules>
    <remove name="AspNetCoreModuleV2" />
    <add name="AspNetCoreModuleV2" />
  </modules>

When I commented out this code, the app worked on Azure.

0

For those of you who hit this stackoverflow entry because it ranks high for the phrase:

The page cannot be displayed because an internal server error has occurred.

In my personal situation with this exact error message, I had turned on python 2.7 thinking I could use some python with my .NET API. I then had that exact error message when I attempted to deploy a vanilla version of the API or MVC from visual studio pro 2013. I was deploying to an azure cloud webapp.

Hope this helps anyone with my same experience. I didn't even think to turn off python until I found this suggestion.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
SamMonk
  • 1,212
  • 9
  • 8