500内部服务器错误请求.Net MVC 3站点中的任何资源文件(css,js,images)

Dan*_*man 8 web-config asp.net-mvc-3 windows-server-2012

更新:我尝试过的事情 - 请参阅下面的答案以获得解决方案

  1. 我安装了一个新的MVC3站点,它正确地提供了资源.这消除了machine.config设置作为一个问题.
  2. 然后我在web.config中逐段查看web.config中是否有任何特定的更改导致了问题.当配置相同时,新鲜的网站仍然有效,旧网站仍然破碎.
  3. 我卸载了IIS,重新安装了IIS,然后再次安装了应用程序,试图清除任何挥之不去的设置.还是蠢蠢欲动.
  4. 然后我使用publish(而不是msi deploy)到新目录.我使用iis选项在完全相同的代码的新目录上"创建应用程序".事情很完美.
  5. 我假设了文件权限,因此我删除了违规目录,并将新工作版本重命名为旧目录名称.网站仍然被塞了.这使我假设一些不在machine.config或web.config中的iis设置是责备.
  6. 我使用IIS 6 Metabase资源管理器(是的,我在IIS 8网站上使用它)并且看到了很多不在工作站点中的条目.在逐个删除后,我发现在我们的MSI安装过程中添加的"scriptMaps"条目导致了问题.添加此选项是为了在安装期间自动添加通配符映射.它适用于IIS6,但显然不适用于IIS8.

我们有一个看起来像一个应用程序的webforms和MVC3应用程序.这部署在许多环境(2003,2008,Win 7)中并且正常运行.我刚刚在新的Windows Server 2012计算机上设置了这些应用程序,除了获取MVC站点的资源文件外,一切正常.浏览器获得了

500 Internal Server Error
Server Application Unavailable

The web application you are attempting to access on this web server is currently unavailable.  Please hit the "Refresh" button in your web browser to retry your request.

Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur. 
Run Code Online (Sandbox Code Playgroud)

资源在_layout.cshtml中引用

<head>
    <meta http-equiv='X-UA-Compatible' content='IE=EmulateIE8' />
    <title>@this.Title</title>
    <script type="text/javascript" src="@Url.Content("~/Scripts/2012.2.607/jquery-1.7.1.min.js")"></script>    
    <script type="text/javascript" src="/Sentri7/scripts/jquery-p1s.banner.js"></script>
    <script type="text/javascript" src="/Sentri7/scripts/jquery-p1s.patientsearch.js"></script>
    <link type="text/css" rel="stylesheet" href="/sentri7/content/jquery-p1s.patientsearch.css"></link>
    <link type="text/css" rel="stylesheet" href="/sentri7/content/jquery-p1s.banner.css" />
    <link type="text/css" rel="stylesheet" href="/quantifi/resources/application/css/jqueryui/jquery-ui-1.7.2.custom.css" />
    <link type="text/css" rel="stylesheet" href="/quantifi/resources/application/css/styles.css" />
    @(RenderSection("PageHead", required: false))
</head>
Run Code Online (Sandbox Code Playgroud)

以及使用telerik scriptmanager:

@{
    Title = "Reportable Conditions";
    SelectedSubTab = SubTabIndex.Reportables;
    Html.Telerik().ScriptRegistrar().DefaultGroup(dg => dg
        .Add("~/Scripts/ReportableConditions/List.js")
        .Add("~/Scripts/ClientObjects/GridSettings.js"))
        .OnDocumentReady("bootStrapUI()");
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试直接导航到javascript文件,我会得到同样的错误:

http://[server]/S7D/Scripts/2012.2.607/jquery-1.7.1.min.js
Run Code Online (Sandbox Code Playgroud)

一些奇怪的东西:

  1. 如果我IISReset并点击js文件,它将只工作第一个请求.

  2. 从服务器上的另一个(webforms)站点(相同的应用程序池)请求的任何js,css或image都可以正常工作.

  3. 事件日志中没有与此500错误相关的内容.

我已经尝试向应用程序池运行的用户添加权限完全权限.我还为[Machine]\IUSR添加了文件权限.

这是我的web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <configSections>
    <sectionGroup name="telerik">
      <section name="webAssets" type="Telerik.Web.Mvc.Configuration.WebAssetConfigurationSection, Telerik.Web.Mvc" requirePermission="false" />
    </sectionGroup>
    <sectionGroup name="spring">
      <section name="typeAliases" type="Spring.Context.Support.TypeAliasesSectionHandler, Spring.Core" />
      <section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web" />
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
    </sectionGroup>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <spring>
    <context>
      <!-- Load web.config definition ** This resource reference is essential to define objects in the web.configs -->
      <resource uri="config://spring/objects" />
      <resource uri="assembly://CAS2/CAS2.CASLibDAO/_SpringObjects.xml" />
      <resource uri="file://~/App_Data/MvcApplicationContext.xml" />
      <resource uri="assembly://P1S.S7D.Core/P1S.S7D.Core.ApplicationContext/ApplicationContext-Common.xml" />
      <resource uri="assembly://P1S.S7D.Core/P1S.S7D.Core.ApplicationContext/ApplicationContext-DAO.xml" />
      <resource uri="assembly://P1S.S7D.Core/P1S.S7D.Core.ApplicationContext/ApplicationContext.xml" />
      <resource uri="assembly://P1S.S7D.Core/P1S.S7D.Core.ApplicationContext/Services.xml" />
      <resource uri="assembly://P1S.S7D.Common/P1S.S7D.Common.ApplicationContext/ApplicationContext-AuthModule.xml" />
      <resource uri="assembly://P1S.S7D.Common/P1S.S7D.Common.ApplicationContext/ApplicationContext-Web-Common.xml" />
      <resource uri="assembly://P1S.S7D.Core/P1S.S7D.Core.ApplicationContext.WCF/ApplicationContext.xml" />
      <resource uri="assembly://P1S.S7D.Core/P1S.S7D.Core.ApplicationContext/ApplicationContext-Circular-Reference-IPReporting.xml" />
    </context>
    <objects xmlns="http://www.springframework.net">
      <!--cached objects-->
    </objects>
  </spring>
  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="P1S.S7D.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="P1S.S7D.Web.Mvc" />
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        <add namespace="Telerik.Web.Mvc.UI" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>



  <appSettings>
    <add key="Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName" value="NHibernateSessionFactory" />
    <add key="Spring.Data.NHibernate.Support.OpenSessionInViewModule.EntityInterceptorObjectName" value="MultiTenantInterceptor" />
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <sessionState allowCustomSqlDatabase="true" mode="SQLServer" sqlConnectionString="Server=dev-ct-nhsn.dev.rph.int;Database=aspstate;User ID=UID;Password=*****; Application Name=S7DSharedSession" />
     <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>
    <membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>
    <roleManager enabled="false">
      <providers>
        <clear />

        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>
    <pages pageBaseType="P1S.S7D.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="P1S.S7D.Web.Mvc" />
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        <add namespace="Telerik.Web.Mvc.UI" />
      </namespaces>
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </controls>
    </pages>
    <httpHandlers>
      <add verb="GET,HEAD" path="asset.axd" validate="false" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc" />
    </httpHandlers>
    <httpModules>
      <add name="AuthenticationModule" type="Web.Handlers.AuthenticationModule,P1S.S7D.Web.Mvc" />
      <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" />
      <add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate31" />

    </httpModules>
        <customErrors mode="Off" />

  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" />
      <add name="AuthenticationModule" type="Web.Handlers.AuthenticationModule,P1S.S7D.Web.Mvc" />
      <add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate31" />

    </modules>
    <!--    -->
    <handlers>
      <remove name="asset" />
      <add name="asset" preCondition="integratedMode" verb="GET,HEAD" path="asset.axd" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc" />
    </handlers>

  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="NHibernate" culture="neutral" publicKeyToken="aa95f207798dfdb4" />
        <bindingRedirect oldVersion="3.1.0.4000" newVersion="3.3.1.4000" />
      </dependentAssembly>
    </assemblyBinding>    
  </runtime>
  <telerik>
    <webAssets useTelerikContentDeliveryNetwork="false" />
  </telerik>
</configuration>
Run Code Online (Sandbox Code Playgroud)

所有资源,无论是使用Telerik还是使用脚本标记添加它们都会产生500错误.控制器和视图正确显示(没有样式或javascript)

编辑:

注册路线:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        RouteTable.Routes.RouteExistingFiles = false;
        routes.MapRoute(
           "Default", // Route name
           "{controller}/{action}/{id}", // URL with parameters
           new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
       );
    }
Run Code Online (Sandbox Code Playgroud)

Vai*_*arg 22

当我将本地站点(Windows 7)发布到服务器(Windows 2012)时,我遇到了同样的错误.

我的本地IIS添加了以下代码:

<staticContent>
  <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
  <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff" />
</staticContent>
Run Code Online (Sandbox Code Playgroud)

我在Win 2012上需要的地方

<staticContent>
    <remove fileExtension=".woff" />
    <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
    <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff" />
</staticContent>
Run Code Online (Sandbox Code Playgroud)

似乎Win2012上的新版IIS已经添加了.woff,而不是给我任何细节,它只是500!

  • 就我而言,我也必须删除 woff2。 (2认同)

Dan*_*man 4

正如我的编辑中提到的。问题是我在 IIS 6 Metabase Explorer 中发现的 IIS 设置不正确。

我使用了 IIS 6 元数据库浏览器(是的,我在 IIS 8 站点上使用了它),并看到了很多不在工作站点中的条目。逐一删除后,我发现是在我们的 MSI 安装过程中添加的“scriptMaps”条目导致了问题。添加此选项是为了在安装过程中自动添加通配符映射。它可以在 IIS6 上运行,但显然不能在 IIS8 上运行。

我不确定为什么文件会在第一个请求时正确提供,但在后续请求中不会正确提供,但删除该条目有效。我在 IIS GUI 中找不到“ScriptMaps”设置,但它可能就在某个地方。

  • 对于我们来说,错误是在 web.config (woff) 中添加了静态内容 mimemap,该静态内容还必须安装在我们的 Azure Web 服务的计算机级别。一旦我们首先添加了删除元素,问题就解决了,因此 500 个错误也得到了解决。 (7认同)