【问题标题】:Error when deployed an MVC site in Azure在 Azure 中部署 MVC 站点时出错
【发布时间】:2015-05-12 08:49:58
【问题描述】:

最近,我将一个在 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 中就不会了。

任何线索,helo,方法?

【问题讨论】:

  • 您能否详细说明您收到的错误消息?
  • 您可能有一个未处理的异常,可能是由于数据库连接字符串不正确(这就是为什么它可以在本地工作,但不是在部署时)。您看到的屏幕告诉您可以更新 web.config 的 &lt;customErrors /&gt; 部分以查看实际错误是什么。虽然您可以暂时执行此操作以在 Azure 上查看问题,但不建议将其用于实时站点。

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


【解决方案1】:

在花时间搜索发生了什么之后,我找到了解决方案。然而,另一个问题来了。

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

嗯,这里的问题是,出于某种原因,代码优先的数据迁移抛出了一个未被捕获的异常。我在 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 表中不存在,说明这些列不存在。即使我在本地添加了这些列。还是想办法解决这个问题。我想我会为此创建另一个帖子。

希望这对其他人有所帮助

【讨论】:

    猜你喜欢
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多