简体   繁体   English

在Azure云服务中看不到应用程序错误

[英]Unable to see application errors in Azure cloud service

So finally I get my MVC app published to the Azure cloud service. 所以最后我将我的MVC应用发布到Azure云服务。 My database is up there too. 我的数据库也在那里。 I can run the app locally after adding WindowsAzure project to my solution and adding my 2 projects (model and web) as Roles. 在将WindowsAzure项目添加到我的解决方案并将我的2个项目(模型和Web)添加为Roles之后,我可以在本地运行该应用程序。

But when I run the URL I get error : 但是当我运行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. 但是,可以由运行在本地服务器计算机上的浏览器查看它。

So I set and re-publish but still I get the same error 所以我设置并重新发布,但仍然收到相同的错误

I need to force Azure to tell me whats happening and reveal the error, anyone any idea? 我需要强迫Azure告诉我发生了什么并显示错误,有人知道吗?

http://bizoptcloudservice01.cloudapp.net http://bizoptcloudservice01.cloudapp.net

No there is no log built into Azure cloud services. 没有,Azure云服务中没有内置日志。 You can implement your own but that involves some implementation. 您可以自己实现,但这需要一些实现。 In my solution I have a custom error page that I created. 在我的解决方案中,我创建了一个自定义错误页面。 My web config looks like so: 我的网络配置如下所示:

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

I have a view in my View/Shared dir named "Error.cshtml". 我在“查看/共享”目录中有一个名为“ Error.cshtml”的视图。 With the config above it is displayed whenever I have an error in my application. 使用上面的配置,只要我的应用程序中出现错误,它就会显示出来。

@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>  

Also for the above to work you need to add this to your Global.ascx.cs. 同样,要使上述方法起作用,您需要将其添加到Global.ascx.cs中。 It defines the default behavior for your application when there is an error. 它定义了出现错误时应用程序的默认行为。 Like so: 像这样:

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

Here is a blog post that talks about it in some more details. 这是一篇博客文章,其中讨论了更多详细信息。

That post and this answer also go into logging errors. 该帖子和此答案也进入了记录错误。 If you want to go that route that should get you started: 如果您想走那条路线,可以开始使用:

Setting HTTP Status in ASP.NET MVC controller results does not render view 在ASP.NET MVC控制器结果中设置HTTP状态不会呈现视图

Check that you're not overwriting your web.config setting with transforms.The Visual Studio 2012 template for MVC projects automatically adds this line to the web.config.release file: 检查您是否没有用转换覆盖web.config设置。用于MVC项目的Visual Studio 2012模板会自动将此行添加到web.config.release文件中:

Your web.config is probably being transformed when the app is published. 发布应用程序时,您的web.config可能正在转换。

Edit: Also, you might want to check out ELMAH, it's a great logging tool, very easy to add to your project and will let you see lost of info on each error: 编辑:另外,您可能想检查一下ELMAH,它是一个很棒的日志记录工具,非常容易添加到您的项目中,并且可以让您看到每个错误的信息丢失:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM