asp.net-mvc - 无法查看 Azure 云服务中的应用程序错误

标签 asp.net-mvc azure

最终我将 MVC 应用程序发布到 Azure 云服务。我的数据库也在那里。将 WindowsAzure 项目添加到我的解决方案并将我的 2 个项目(模型和 Web)添加为角色后,我可以在本地运行该应用程序。

但是当我运行 URL 时出现错误:

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.

所以我设置并重新发布,但仍然遇到相同的错误

我需要强制 Azure 告诉我发生了什么并揭示错误,有人知道吗?

http://bizoptcloudservice01.cloudapp.net

最佳答案

不,Azure 云服务中没有内置日志。您可以实现自己的,但这涉及一些实现。在我的解决方案中,我创建了一个自定义错误页面。我的网络配置如下所示:

<customErrors mode="On" defaultRedirect="~/error/Error">
 ...
</customErrors>

我的 View /共享目录中有一个名为“Error.cshtml”的 View 。使用上面的配置,只要我的应用程序出现错误,它就会显示。

@model System.Web.Mvc.HandleErrorInfo

@{
    ViewBag.Title = "Error";
}

<h2> Sorry, an error occurred while processing your request!!?!</h2>

<div>
    Try again.  If the problem persists...
    Close all your browser windows and re-login to the application. If the problem still persists...
    Contact the service desk with the details of this error.
</div>

        <h3>Error Details</h3>
        <div>
        <strong>
        @Model.Exception.Message
        </strong>
            <pre>@Model.Exception.StackTrace</pre>
    </div>
    </div>
</div>  

此外,为了使上述工作正常,您需要将其添加到 Global.ascx.cs 中。它定义了应用程序出现错误时的默认行为。就像这样:

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute()); 
    }

Here is a blog post that talks about it in some more details.

那篇文章和这个答案也涉及记录错误。如果您想走那条应该让您入门的路线:

Setting HTTP Status in ASP.NET MVC controller results does not render view

关于asp.net-mvc - 无法查看 Azure 云服务中的应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14318949/

相关文章:

sql-server - 是否可以在 Azure SQL 数据库中选择标签?

azure - Windows 实例的 Amazon EC2 价格?

c# - 如何在 azure 上为 asp 创建 SQL 服务器?

c# - 在 C# ASP.NET MVC 5 中将图像上传到 S3

c# - ASP.NET MVC NonAction 含义

asp.net-mvc - 当 UserId 类型更改为 Int 时重命名 EF6 身份表问题

azure - CosmosDB 容器未创建

azure - 如何更改 Microsoft Integration Runtime CONfiguration Manager 中的数据工厂?

asp.net-mvc - 使用 Azure 中同步的 Active Directory 验证用户(包括组)?

c# - 在 ASP.NET MVC 站点上设置 Wordpress 永久链接