【发布时间】: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="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" 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="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.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