none
IIS 8.5 - 500 Server Error when serving Static content (PNGs/JS/CSS/etc.) RRS feed

  • Question

  • Background

    I am deploying a C# MVC/WebApi-based web application to a new platform (Windows 2012 R2 Standard - IIS 8.5). The web application itself responds normally with no errors with the core code, connectivity to the database, etc.

    Problem

    When any client via a web browser accesses the web application all static files (CSS/Font/JS/Image) cannot be displayed, a 500 Internal Server Error status code is returned for the requests for these files.

    However, if the CSS/JS files are minified and bundles via C# bundling functionality these requests are returned correctly. Fonts and images still do not display.

    Troubleshooting

    Verified the following:

    • Directory Browsing and Static Content features are enabled under Web Server (IIS) -> Web Server -> Common HTTP Features
    • StaticFile is defined as a HandlerMpping for the web application with the following settings:
      • Path: *
      • State: Enabled
      • Path Type: File or Folder
      • Handler: StaticFileModule,DefaultDocumentModule,DirectoryListingModule
      • Entry Type: Inherited
    • The Application Pool user for the web application has read access to the directory, subdirectories and all files.

    Reference

    web.config

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=301879
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
      </configSections>
      <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
      <system.web>
        <httpRuntime maxUrlLength="1000" maxQueryStringLength="10000" targetFramework="4.5.2" requestValidationMode="2.0" requestPathInvalidCharacters="" enableVersionHeader="false" relaxedUrlToFileSystemMapping="true" />
        <compilation targetFramework="4.5.2" />
        <httpCookies httpOnlyCookies="true" requireSSL="false" />
        <trace writeToDiagnosticsTrace="false" enabled="false" pageOutput="false" localOnly="true" />
        <authentication mode="Windows" />
        <authorization>
          <deny users="?" />
        </authorization>
        <customErrors mode="Off"></customErrors>
      </system.web>
      <system.webServer>
        <handlers>
          <remove name="WebDAV" />
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <remove name="OPTIONSVerbHandler" />
          <remove name="TRACEVerbHandler" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
        <httpCompression directory="[[REDACTED]]\IISContentCompression" minFileSizeForComp="1024">
          <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
          <dynamicTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="application/json" enabled="true" />
            <add mimeType="*/*" enabled="false" />
          </dynamicTypes>
          <staticTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="application/json" enabled="true" />
            <add mimeType="*/*" enabled="false" />
          </staticTypes>
        </httpCompression>
        <httpErrors existingResponse="PassThrough" errorMode="Custom">
          <!-- Catch IIS 404 error due to paths that exist but shouldn't be served (e.g. /controllers, /global.asax) or IIS request filtering (e.g. bin, web.config, app_code, app_globalresources, app_localresources, app_webreferences, app_data, app_browsers) -->
          <remove statusCode="404" subStatusCode="-1" />
          <error statusCode="404" subStatusCode="-1" path="/notfound" responseMode="ExecuteURL" />
          <remove statusCode="500" subStatusCode="-1" />
          <error statusCode="500" subStatusCode="-1" path="/error" responseMode="ExecuteURL" />
        </httpErrors>
        <urlCompression doStaticCompression="true" doDynamicCompression="true" />
        <directoryBrowse enabled="false" />
        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="true">
          <remove name="WebDAVModule" />
        </modules>
        <staticContent>
          <!-- Set expire headers to 30 days for static content-->
          <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
          <!-- use utf-8 encoding for anything served text/plain or text/html -->
          <remove fileExtension=".css" />
          <mimeMap fileExtension=".css" mimeType="text/css" />
          <remove fileExtension=".js" />
          <mimeMap fileExtension=".js" mimeType="text/javascript" />
          <remove fileExtension=".json" />
          <mimeMap fileExtension=".json" mimeType="application/json" />
          <remove fileExtension=".rss" />
          <mimeMap fileExtension=".rss" mimeType="application/rss+xml; charset=UTF-8" />
          <remove fileExtension=".html" />
          <mimeMap fileExtension=".html" mimeType="text/html; charset=UTF-8" />
          <remove fileExtension=".xml" />
          <mimeMap fileExtension=".xml" mimeType="application/xml; charset=UTF-8" />
          <!-- HTML5 Audio/Video mime types-->
          <remove fileExtension=".mp3" />
          <mimeMap fileExtension=".mp3" mimeType="audio/mpeg" />
          <remove fileExtension=".mp4" />
          <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
          <remove fileExtension=".ogg" />
          <mimeMap fileExtension=".ogg" mimeType="audio/ogg" />
          <remove fileExtension=".ogv" />
          <mimeMap fileExtension=".ogv" mimeType="video/ogg" />
          <remove fileExtension=".webm" />
          <mimeMap fileExtension=".webm" mimeType="video/webm" />
          <!-- Proper svg serving. Required for svg webfonts on iPad -->
          <remove fileExtension=".svg" />
          <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
          <remove fileExtension=".svgz" />
          <mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
          <!-- HTML4 Web font mime types -->
          <!-- Remove default IIS mime type for .eot which is application/octet-stream -->
          <remove fileExtension=".eot" />
          <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
          <remove fileExtension=".ttf" />
          <mimeMap fileExtension=".ttf" mimeType="application/x-font-ttf" />
          <remove fileExtension=".ttc" />
          <mimeMap fileExtension=".ttc" mimeType="application/x-font-ttf" />
          <remove fileExtension=".otf" />
          <mimeMap fileExtension=".otf" mimeType="font/opentype" />
          <remove fileExtension=".woff" />
          <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
          <remove fileExtension=".crx" />
          <mimeMap fileExtension=".crx" mimeType="application/x-chrome-extension" />
          <remove fileExtension=".xpi" />
          <mimeMap fileExtension=".xpi" mimeType="application/x-xpinstall" />
          <remove fileExtension=".safariextz" />
          <mimeMap fileExtension=".safariextz" mimeType="application/octet-stream" />
          <!-- Flash Video mime types-->
          <remove fileExtension=".flv" />
          <mimeMap fileExtension=".flv" mimeType="video/x-flv" />
          <remove fileExtension=".f4v" />
          <mimeMap fileExtension=".f4v" mimeType="video/mp4" />
          <!-- Assorted types -->
          <remove fileExtension=".ico" />
          <mimeMap fileExtension=".ico" mimeType="image/x-icon" />
          <remove fileExtension=".webp" />
          <mimeMap fileExtension=".webp" mimeType="image/webp" />
          <remove fileExtension=".htc" />
          <mimeMap fileExtension=".htc" mimeType="text/x-component" />
          <remove fileExtension=".vcf" />
          <mimeMap fileExtension=".vcf" mimeType="text/x-vcard" />
          <remove fileExtension=".torrent" />
          <mimeMap fileExtension=".torrent" mimeType="application/x-bittorrent" />
          <remove fileExtension=".cur" />
          <mimeMap fileExtension=".cur" mimeType="image/x-icon" />
          <remove fileExtension=".webapp" />
          <mimeMap fileExtension=".webapp" mimeType="application/x-web-app-manifest+json; charset=UTF-8" />
        </staticContent>
        <httpProtocol>
          <customHeaders>
            <remove name="X-Powered-By" />
            <add name="X-Powered-By" value="[[REDACTED]]" />
            <add name="X-UA-Compatible" value="IE=Edge,chrome=1" />
            <add name="X-Content-Type-Options" value="nosniff" />
          </customHeaders>
        </httpProtocol>
        <security>
          <requestFiltering>
            <requestLimits maxUrl="20000" maxQueryString="1073741824" maxAllowedContentLength="1073741824" />
          </requestFiltering>
          <authentication>
            <windowsAuthentication enabled="true" />
            <anonymousAuthentication enabled="false" />
          </authentication>
        </security>
      </system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
            <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="mssqllocaldb" />
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
      <connectionStrings>
        <add name="PP" connectionString="[[REDACTED]]" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <location path="[[REDACTED]]">
        <system.web>
          <!--<authentication mode="None"/>-->
          <authorization>
            <allow users="?" />
          </authorization>
        </system.web>
        <system.webServer>
          <security>
            <authentication>
              <!--<anonymousAuthentication enabled="true" />-->
            </authentication>
          </security>
        </system.webServer>
      </location>
      <log4net>
        <root>
          <level value="ALL" />
          <appender-ref ref="ApplicationReportingDB" />
        </root>
        <appender name="ApplicationReportingDB" type="log4net.Appender.AdoNetAppender">
          <bufferSize value="1" />
          <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          <connectionString value="[[REDACTED]]" />
          <commandText value="INSERT INTO ErrorLog ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
          <parameter>
            <parameterName value="@log_date" />
            <dbType value="DateTime" />
            <layout type="log4net.Layout.RawTimeStampLayout" />
          </parameter>
          <parameter>
            <parameterName value="@thread" />
            <dbType value="String" />
            <size value="255" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%thread" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@log_level" />
            <dbType value="String" />
            <size value="50" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%level" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@logger" />
            <dbType value="String" />
            <size value="255" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%logger" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@message" />
            <dbType value="String" />
            <size value="4000" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%message" />
            </layout>
          </parameter>
          <parameter>
            <parameterName value="@exception" />
            <dbType value="String" />
            <size value="2000" />
            <layout type="log4net.Layout.ExceptionLayout" />
          </parameter>
          <parameter>
            <parameterName value="[[REDACTED]]" />
            <dbType value="String" />
            <size value="255" />
            <layout type="log4net.Layout.PatternLayout">
              <conversionPattern value="%property{CustomColumn}" />
            </layout>
          </parameter>
        </appender>
      </log4net>
      <location path="[[REDACTED]]">
        <system.web>
          <authorization>
            <allow users="?" />
          </authorization>
        </system.web>
        <system.webServer>
          <security>
            <authentication>
              <anonymousAuthentication enabled="true" />
            </authentication>
          </security>
        </system.webServer>
      </location>
    </configuration>


    Thursday, May 18, 2017 4:26 PM

Answers

All replies