将Azure MVC5网站部署到Azure,获得500个内部服务器错误

问题描述:

我使用本地数据库在本地构建了ASP.NET MVC5网站。我明白了这一点,我希望将它引入到Azure Web服务中,因此我启用了Azure网站并设置为从Visual Studio Online Git库中进行部署。部署发生,但访问页面仅生成'处理请求时发生错误'。错误。将Azure MVC5网站部署到Azure,获得500个内部服务器错误

如果我看看日志中我得到列出以下错误:

  1. MODULE_SET_RESPONSE_ERROR_STATUS

Warning ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The operation completed successfully. (0x0)", ConfigExceptionInfo=""

数据库连接字符串已被替换为AzureSqlDatabase连接字符串,所以我试图检查那里。该字符串'看起来'很好,但我注意到,当我在调试模式下运行应用程序时,它以某种方式使用原始本地Sql数据库,尽管该连接字符串不再在代码中!

我已经尝试了SO中列出的一些建议,包括启用详细日志记录和重新推送web.config文件,但似乎没有任何工作。关于如何追踪和解决此问题的任何想法?

编辑: 随着MFanto的帮助,我发现应用程序仍然使用旧的本地SQL数据库的连接字符串。 (数据源= \ SQLEXPRESS;初始目录= HouseOfBurt.Models.DataContext;集成安全性= TRUE; MultipleActiveResultSets =真)

在Web.config如下:

<?xml version="1.0"?> 

<configuration> 
    <configSections> 
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> 
     <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> 
    </sectionGroup> 
    </configSections> 

    <system.web.webPages.razor> 
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <pages pageBaseType="System.Web.Mvc.WebViewPage"> 
     <namespaces> 
     <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="Application" /> 
     <add namespace="Application.Models" /> 
     </namespaces> 
    </pages> 
    </system.web.webPages.razor> 

    <appSettings> 
    <add key="webpages:Enabled" value="false" /> 
    </appSettings> 

    <system.webServer> 
    <handlers> 
     <remove name="BlockViewHandler"/> 
     <add name="BlockViewHandler" path="*.cshtml" verb="*" 
      preCondition="integratedMode" 
      type="System.Web.HttpNotFoundHandler" /> 
    </handlers> 
    </system.webServer> 
</configuration> 

的Web.Debug。配置Config(密码改性当然)

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <!-- 
    In the example below, the "SetAttributes" transform will change the value of 
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
    finds an attribute "name" that has a value of "MyDB". 

    <connectionStrings> 
     <add name="MyDB" 
     connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
     xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> 
    </connectionStrings> 
    --> 
    <connectionStrings> 
    <add name ="DataContextContainer" connectionString="Server=tcp:r0c0umg8th.database.windows.net,1433;Database=HouseOfBurt;User [email protected];Password=password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.EntityClient"/> 
    </connectionStrings> 

    <system.web> 
    <compilation xdt:Transform="RemoveAttributes(debug)" /> 
    <!-- 
     In the example below, the "Replace" transform will replace the entire 
     <customErrors> section of your Web.config file. 
     Note that because there is only one customErrors section under the 
     <system.web> node, there is no need to use the "xdt:Locator" attribute. 

     <customErrors defaultRedirect="GenericError.htm" 
     mode="RemoteOnly" xdt:Transform="Replace"> 
     <error statusCode="500" redirect="InternalError.htm"/> 
     </customErrors> 
    --> 
    </system.web> 
</configuration> 

EDIT2:所述的DbContext类的添加:

public class DataContext : DbContext 
    { 
     #region Tables 

     public DbSet<Article> Articles { get; set; } 
     public DbSet<Category> Categories { get; set; } 
     public DbSet<Link> Links { get; set; } 

     #endregion Tables 

     #region Public Methods 

     #endregion Public Methods 

    } 
+1

如何更换连接字符串?通过门户上的Azure网站设置,还是使用web.config转换(例如web.debug.config和web.release.config)?您是否尝试过远程调试天蓝色网站以查看其中断的位置? – mfanto 2014-08-31 16:23:42

+0

我改变了实际的web.Config。我会看看我是否可以进行远程会话。 – ChargerIIC 2014-08-31 19:54:15

+0

无法获取调试会话进行连接,但确实报告了SqlException。 web.config,web.debug.config和web.release.config都具有指向实体框架的相同连接字符串。尽管本地调试仍然连接到本地SQL实例,所以我做错了什么。任何想法是什么? – ChargerIIC 2014-08-31 23:38:58

您的DbContext您发布的类别名为DataContext,但示例中的连接字符串为DataContextContainer

如果未明确提供连接字符串,实体框架将查找名称与完全匹配的连接字符串到DBContext的名称;其他约定将尝试使用基于代码的连接字符串,目标为SQLExpress。

更改连接字符串名称似乎已解决问题。

有关实体框架连接字符串约定的更多信息可在http://msdn.microsoft.com/en-us/data/jj592674找到。