Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC / IIS 7.5: 500 Internal Server Error for static content only

An ASP.NET MVC project running under IIS 7.5 (but problem may exist on earlier versions and non-MVC sites) which was previously working has started returning 500 Internal Server Error but only for content handled by the static handler - images, pages etc. handled by MVC itself through a controller work fine.

I know what caused it - I am documenting this in case somebody else has the same problem.

like image 351
nrkn Avatar asked Dec 03 '12 05:12

nrkn


People also ask

How do I fix 500 Internal server error in IIS?

IIS error The error 500.19 is an internal server error often occurring on a server using Microsoft IIS software. It indicates that the configuration data for the page is invalid. To solve the issue, delete the malformed XML element from the Web. config file or from the ApplicationHost.

How do you fix 500 Internal server error There is a problem with the resource you are looking for and it Cannot be displayed?

500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed. To resolve this issue, set the Enable 32-bit Applications to "False": Open the Internet Information Services (IIS) Manager.

How do you fix the page Cannot be displayed because an internal server error has occurred?

The page cannot be displayed because an internal server error has occurred. 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.

What does the 500 internal server error code mean in IIS website?

HTTP Error 500 message indicates that a problem has occurred on the Web server that hosts the Web site at the time the error is returned.


2 Answers

I enabled Failed Request tracing and after searching through the (enormous) log, I discovered this:

 <EventData>
  <Data Name="ContextId">{00000000-0000-0000-3700-0080010000FC}</Data>
  <Data Name="ModuleName">CustomErrorModule</Data>
  <Data Name="Notification">536870912</Data>
  <Data Name="HttpStatus">500</Data>
  <Data Name="HttpReason">Internal Server Error</Data>
  <Data Name="HttpSubStatus">19</Data>
  <Data Name="ErrorCode">2147942583</Data>
  <Data Name="ConfigExceptionInfo">
    \\?\C:\Websites\xxx\www\web.config ( 58) :Cannot add duplicate collection 
    entry of type &apos;mimeMap&apos; with unique key attribute 
    &apos;fileExtension&apos; set to &apos;.woff&apos;
  </Data>
 </EventData>

What has happened is, a new Mime type for serving web-fonts (.woff) had been explicity added to the site.

Later on, the new Mime type (.woff) had also been added to the global IIS mime types.

Instead of the website setting overriding the global setting, an exception was being thrown.

like image 164
nrkn Avatar answered Oct 19 '22 06:10

nrkn


Always remove any mimetype you want to add, just in case it's already defined at the IIS/server level, eg:

<staticContent>
  <remove fileExtension=".otf" />
  <mimeMap fileExtension=".otf" mimeType="application/x-font-otf" />
</staticContent>
like image 32
Steven Quick Avatar answered Oct 19 '22 06:10

Steven Quick