【问题标题】:error 500: ManagedPipelineHandler, deploying web api mvc 4 on azure错误 500:ManagedPipelineHandler,在 azure 上部署 web api mvc 4
【发布时间】:2016-05-11 23:03:35
【问题描述】:

我正在尝试将 WebAPI 项目部署到 azure。

当我有一个没有 SQL 访问权限的方法时,它会在我的浏览器中正确地将结果显示为 JSON。

但是,当我使用实体框架做任何事情并从数据库中获取测试字段时,整个事情都会出错:

 Module ManagedPipelineHandler 
 Notification ExecuteRequestHandler 
 Handler System.Web.Http.WebHost.HttpControllerHandler 
 Error Code 0x00000000 

我尝试过的事情:

  • 在“Azure 计算模拟器”中运行时,一切正常
  • 在调试中使用完全相同的 sql azure 连接字符串时,它运行得很好
  • 当使用 RDP 连接到 webrole 并远程登录到端口 1443 到 SQL azure 服务器时,它连接得很好。 (所以没有防火墙问题)。

接下来我可以尝试什么来找出造成这种情况的原因?

更新: 当我将连接字符串指向本地 SQLEXPRESS 数据库时,它会给出相同的错误。在本地 azure 模拟器上它仍然有效

更新: 显示在本地浏览器上的错误截图(通过 rdp) http://www.proofofconcept.nl/azure_error_screenshot.png

更新: 应大众要求。使用的 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=152368
  -->
<configuration>
  <connectionStrings>

    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />  
    <add name="Entities" connectionString="metadata=res://*/DAL.Coalition.csdl|res://*/DAL.Coalition.ssdl|res://*/DAL.Coalition.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

    <!--
    <add name="ApplicationServices" connectionString="data source=acbdefgh12.database.windows.net;Initial Catalog=MyCatalog;User ID=database_user@acbdefgh12;Password=MyPassword;Encrypt=true;Trusted_Connection=false;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
    <add name="Entities" connectionString="metadata=res://*/DAL.Coalition.csdl|res://*/DAL.Coalition.ssdl|res://*/DAL.Coalition.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=acbdefgh12.database.windows.net;Initial Catalog=MyCatalog;User ID=database_user@acbdefgh12;Password=MyPassword;Encrypt=true;Trusted_Connection=false;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
-->

  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <customErrors mode="Off" />
    <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" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </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>
      <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.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  </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>
  </runtime>
</configuration>

【问题讨论】:

  • 您能否验证事件查看器的 ASP.NET 警告(这些包含实际错误)?我不认为您发布的错误是实际错误。
  • 我打开了事件查看器并单击了应用程序选项卡(这是我应该查看的选项卡吗?)。但是没有为 IIS 记录事件。
  • 您可以尝试在 RDP 会话中访问该网站吗?它可能会输出有关错误的更多信息(o
  • 远程查看时,它只显示内部错误 500。通过 RDP,它给出了我最初提供的错误。我将其截屏并将其添加到问题中
  • 我想你是先做 ef 代码...你有没有尝试过先在天蓝色中创建数据库,然后再针对它运行?

标签: azure web asp.net-mvc-4 asp.net-web-api azure-sql-database


【解决方案1】:

您使用的是 EF CodeFitst 吗?如果有是哪个版本? (4.3 之前的版本确实存在 SQL Azure 问题)?然后观察以下情况:

  • 您的主 DbContext 是命名为“实体”还是使用指向“实体”连接的构造函数重载显式创建它?
  • 您的 my_dbuser@acbdefgh12 用户是否有权访问 MASTER DB?
  • MyCatalog 在您部署软件包之前是否存在?
  • 您的 SQL Azure 防火墙是否规定“允许来自其他 Windows Azure 服务的连接”(请看下面的屏幕截图)(我知道您提到过,但无论如何)?

当任何一个为真时,我都看到了完全相同的错误:

  • my_dbuser@acbdefgh12 无权访问主数据库来创建 MyCatalaog 数据库(以防它不存在)
  • MyCatalog DB 存在,但与 DbContext 模型不同
  • 主 DbContext 的命名与实体不同,并使用默认的无参数构造函数(在这种情况下使用默认的 EF 连接字符串)创建
  • SQL Azure 服务器未配置为接受来自其他 Windows Azure 服务的连接

不幸的是,实际错误没有显示任何有用的信息。正如我所说,当我未能遵守上述声明时,我看到的错误完全相同。

我建议跟踪错误的方法是挂钩/编辑您自动生成的 DbContext 文件,并在连接打开之前明确抛出正在使用的连接字符串的异常,以确保正在使用的连接字符串。

忽略 Web.Config 后更新

不确定这是否相关,但我注意到在您的 web.config 中,如果版本较低,则程序集绑定会强制使用 MVC 3.0:

  <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>
  </runtime>

而我的 MVC 4 的 web.config 与 Web API 项目类型(.NET FX 4.0 / MVC 4)略有不同:

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

【讨论】:

  • 哇..多么有用的东西啊。我得走了,但今晚我会检查你的物品,看看它们是否是成功的关键。
  • 第一句话:不要使用codefirst。防火墙已打开。可以从 azure 角色使用 telnet 连接到它。使用 mysqlexpress 文件时,它仍然无法正常工作。在本地运行时,它可以正常工作,因此没有连接字符串或访问权限问题。
  • 将您的 webconfig 程序集绑定复制粘贴到 webconfig 中,错误也没有变化
  • 我的实体上下文类确实被称为“实体”,所以我想应该可以吧?当我在本地(在天蓝色模拟器中)运行它时它确实有效
  • 如何确保 EF 和 MVC 引用程序集使用“Copy Local=True”并从“添加可部署依赖项”中检查 MVC(右键单击 Web 项目)
【解决方案2】:

非常老的问题,但我的问题很快就将我带到了这个页面。在 Azure webapp、Entity Framework 应用程序上,我遇到了 500 错误,并且在从日志和跟踪中获取任何其他信息时遇到了很多麻烦。

原来我的连接字符串丢失了

MultipleActiveResultSets=true;

属性。一些页面正在工作,而另一些则没有。一旦我添加了这个,所有页面都可以正常工作。

【讨论】:

    猜你喜欢
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    • 2011-11-27
    相关资源
    最近更新 更多