c# - 在 Azure 中部署 MVC 站点时出错

标签 c# asp.net-mvc asp.net-mvc-4 azure

最近,我将一个在VS2013中构建的MVC站点部署到Azure中。事实上,到目前为止我已经完成了 4 次部署。第一棵树部署正常。

直到最后一次部署时,我收到一条错误消息:需要在 web.config 中添加标记。

这很奇怪,因为在本地测试 git 时我没有收到任何错误。直到我将它部署到 Azure。

这是我在 Azure 中运行时遇到的错误:

Runtime Error

Description: An application error occurred on the server. The current    custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

<!-- Web.Config Configuration File -->
   <configuration>
      <system.web>
        <customErrors mode="Off"/>
   </system.web>
</configuration>

Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

<!-- Web.Config Configuration File -->
   <configuration>
      <system.web>
         <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
      </system.web>
   </configuration>

我在上次部署中所做的更改是使用第一个代码创建方法以及数据迁移本身添加一些列。

同样,本地一切正常。但是,一旦进入 Azure,就不再存在了。

有什么线索,嘿,方法吗?

最佳答案

花时间谷歌搜索发生的事情后,我找到了解决方案。然而,另一个问题又来了。

首先,我将标记放入 web.config 中以便查看错误。

嗯,这里的问题是,由于某种原因,Code First 的数据迁移抛出了一个未被捕获的异常。我在 Startup.Auth.cs 文件中添加了以下代码行

OnException = context => {}

欲了解更多信息,请访问:Why is [Owin] throwing a null exception on new project?

这样就可以绕过错误。现在,如果您想知道确切的错误,请输入:

OnException = (context =>{
             throw context.Exception;
             })

您可以看到错误是什么。在我的例子中是:自创建数据库以来支持上下文的模型已更改

我按照此链接的解决方案进行操作:The model backing the <Database> context has changed since the database was created

它以某种方式解决了问题。

由于我向 AspNetUser 表添加了两个新列,这些新列不存在于 Azure 表中,说明这些列不存在。即使我在本地添加了这些列。还是想办法解决这个问题。我想我会为此创建另一篇文章。

希望这对其他人有帮助

关于c# - 在 Azure 中部署 MVC 站点时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28971802/

相关文章:

c# - 如何在 c# 中使用 ffmpeg 向 wav 文件添加额外的 5 秒持续时间

c# - AutoMapper:如何从 String 解析 Int 并可能根据数据类型创建规则?

c# - MVC - 从 View 调用 Controller

asp.net-mvc - MVC 输入日期时间

asp.net-mvc-4 - MVC4 ViewData.TemplateInfo.HtmlFieldPrefix 生成一个额外的点

c# - 如何在 .NET 4 中使用 Console.CancelKeyPress? (在 .NET 3.5 及以下版本中工作正常)

asp.net - 缓存最佳做法

asp.net-mvc - 使用 Glimpse 获取 InvalidCastException,即使它尚未安装。我该如何解决?

asp.net-mvc - MVC : Binding datetime value (bootstrap datetime picker) from view to model

asp.net - 选择哪种模式? Asp.net Mvc 4