简体   繁体   中英

Can the ASP.NET MVC Yellow Screen of Death (YSOD) be generated on demand

As asked here .

I want to know if it is possible to get the YSOD's HTML Rendering for exceptions to be sent by mail WITHOUT the use of ELMAH? I am handling the errors and showing a custom error page to the user. I am also sending the exception general information throught mail, however I really would like to know if I can wrap them into the real built-in YSOD engine of ASP.NET and keep the HTML formatting.

UPDATE1:

I have my custom exceptions (DupplicatedArbsException) that returns a view with the message which i consider "Managed Exceptions". However, if it is a real error that I did not catch, it will return the Error view.

    [HandleError(ExceptionType = typeof(Exception), View = "Error")]
    [HandleError(ExceptionType = typeof(DuplicatedArbsException), View = "ErrorViewArbs")]
    public ActionResult Create(string id, int? version)
    {
         //...
    }

The HandleError Raises which does nothing currently.

    protected override void OnException(ExceptionContext filterContext)
    {
        var ex = filterContext.Exception;
        base.OnException(filterContext);
    }

..

    <customErrors mode="On" defaultRedirect="Error"/>

The exception raised in customErrors mode="off" is the YSOD from asp.net. However, when I turn customErrors mode="on" those exceptions are not wrapped in it's html equivalent but only the exception messages (no html at all).

You could handle the Application_Error event in global.asax which is triggered by the ASP.NET engine every-time an exception is not handled:

protected void Application_Error(object sender, EventArgs e)
{
    var app = (HttpApplication)sender;
    var context = app.Context;
    // get the exception that was unhandled
    Exception ex = context.Server.GetLastError();

    // TODO: log, send the exception by mail
}

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