简体   繁体   中英

Unable to see application errors in Azure cloud service

So finally I get my MVC app published to the Azure cloud service. 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.

But when I run the URL I get 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.

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?

http://bizoptcloudservice01.cloudapp.net

No there is no log built into Azure cloud services. 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". 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. 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

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:

Your web.config is probably being transformed when the app is published.

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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