简体   繁体   English

MVC 4 Azure Web角色:向Web.config中添加“跟踪”元素时出现错误500

[英]MVC 4 Azure web role: Error 500 when adding the “tracing” element to web.config

I'm trying to add diagnostics to an Azure web role by following the example found here: https://www.windowsazure.com/en-us/develop/net/common-tasks/diagnostics/ 我正在尝试通过以下示例将诊断添加到Azure Web角色: https : //www.windowsazure.com/en-us/develop/net/common-tasks/diagnostics/

When I add the tracing element under system.webserver , I see an error when running the website. system.webserver下添加tracing元素时,运行网站时看到错误。 The error can be seen even before a breakpoint in OnStart is hit. 即使在命中OnStart的断点之前也可以看到该错误。

Any ideas? 有任何想法吗?

Here is my web.config file with the problematic section commented out: 这是我的web.config文件,其中有问题的部分已被注释掉:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>    
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet_d368ef657c124d629b2577cb9775791c;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <customErrors mode="Off"></customErrors>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <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.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <machineKey decryption="AES" decryptionKey="F7FA540B4DFD82E5BB196B95D15FF81F740A8B17F626BAF1D0889905ACBF0B60" validation="SHA1" validationKey="740A8B17F626BAF1D0889905ACBF0B609712CDA49DE62168764FF0DCE537184F0535D5D9AD66DEDC740A8B17F626BAF1D0889905ACBF0B609712CDA497DC1ABF" />
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <!--<tracing>
      <traceFailedRequests>
        <add path="*">
          <traceAreas>
            <add provider="ASP" verbosity="Verbose" />
            <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
            <add provider="ISAPI Extension" verbosity="Verbose" />
            <add provider="WWW Server"
            areas="Authentication,
                Security,
                Filter,
                StaticFile,
                CGI,
                Compression,
                Cache,
                RequestNotifications,
                Module"
            verbosity="Verbose" />
          </traceAreas>
          <failureDefinitions statusCodes="400-599" />
        </add>
      </traceFailedRequests>
    </tracing>-->
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

Here is how I solved the issue: 这是我解决问题的方法:

Suddenly the server started printing verbose info about the 500 error (I don't know why, I don't think I changed anything), and then I discovered that the actual error was: 突然服务器开始打印有关500错误的详细信息(我不知道为什么,我认为我没有更改任何内容),然后我发现实际的错误是:

HTTP Error 500.19: HTTP错误500.19:

Cannot add duplicate collection entry of type 'add' with unique key attribute 'path' set to '*' 无法添加唯一键属性“路径”设置为“ *”的类型为“添加”的重复收集条目

The solution to this was to add the following line before the add tag: 解决方案是在add标记之前 add以下行:

<remove path="*"/>

So now the tracing tag looks like this: 因此,现在tracing标记如下所示:

<tracing>
      <traceFailedRequests>
        <remove path="*"/>
        <add path="*">
          <traceAreas>
            <add provider="ASP" verbosity="Verbose" />
            <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
            <add provider="ISAPI Extension" verbosity="Verbose" />
            <add provider="WWW Server"
            areas="Authentication,
                Security,
                Filter,
                StaticFile,
                CGI,
                Compression,
                Cache,
                RequestNotifications,
                Module"
            verbosity="Verbose" />
          </traceAreas>
          <failureDefinitions statusCodes="400-599" />
        </add>
      </traceFailedRequests>
    </tracing>

and this seems to work fine. 这似乎工作正常。

I noticed that you're referencing Microsoft.WindowsAzure.Diagnostics Version=1.8.0.0 which comes part of the October Azure SDK to get the Azure listener. 我注意到您正在引用Microsoft.WindowsAzure.Diagnostics Version = 1.8.0.0,该版本是十月Azure SDK的一部分,用于获取Azure侦听器。 Do you have the Storage client library 1.7 included in your project? 您的项目中是否包含存储客户端库1.7? The Azure diagnostics library 1.8 relies on the older storage client library 1.7 (not 2.0 which was released with the sdk) Azure诊断库1.8依赖于较旧的存储客户端库1.7(而非与SDK一起发布的2.0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM