12

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

  1. 我安装了一个新的 MVC3 站点,它正确地提供了资源。这消除了 machine.config 设置的问题。
  2. 然后,我在 web.config 中逐节查看 web.config 中是否有任何特定更改导致问题。当配置相同时,新站点仍然有效,旧站点仍然损坏。
  3. 我卸载了 IIS,重新安装了 IIS,然后再次安装了应用程序,以试图清除任何挥之不去的设置。还是很无聊。
  4. 然后我使用发布(而不是 msi 部署)到新目录。我使用 iis 选项在已损坏的完全相同代码的新目录上“创建应用程序”。事情很顺利。
  5. 我假设了文件权限,所以我删除了有问题的目录并将新的工作版本重命名为旧目录名称。网站仍然很无聊。这让我假设某些不在 machine.config 或 web.config 中的 iis 设置是罪魁祸首。
  6. 我使用了 IIS 6 元数据库资源管理器(是的,我在 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. 

_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>

以及使用 Telerik 脚本管理器:

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

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

http://[server]/S7D/Scripts/2012.2.607/jquery-1.7.1.min.js

一些奇怪的东西:

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

  2. 从服务器上的另一个(网络表单)站点(相同的应用程序池)请求的任何 js、css 或图像都可以正常工作。

  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>

所有资源,无论是使用 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
       );
    }
4

3 回答 3

24

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

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

<staticContent>
  <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
  <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff" />
</staticContent>

我在 Win 2012 上需要这个的地方

<staticContent>
    <remove fileExtension=".woff" />
    <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
    <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff" />
</staticContent>

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

于 2015-09-07T05:19:05.030 回答
4

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

我使用了 IIS 6 元数据库资源管理器(是的,我在 IIS 8 站点上使用了它)并且看到了很多不在工作站点中的条目。一个一个删除后,我发现是我们MSI安装过程中添加的“scriptMaps”条目导致了问题。这是为了在安装过程中自动添加通配符映射而添加的。它适用于 IIS6,但显然不适用于 IIS8。

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

于 2013-09-09T20:39:22.627 回答
1

在我的情况下,我在 Window 8.0 上运行我的应用程序时遇到了这个错误。

在 IIS 中将 .woff 的 mini 类型从 'font/x-woff' 更改为 'application/x-font-woff' 后,它运行良好。(更改 mini 类型后,我的 web 配置将 '' 添加到 staticContent自动地)

于 2014-05-07T08:23:53.867 回答