How to set up an exception page for developers in Asp.Net Core?

The ConfigureStartup.cs file method often contains code that looks like this:

if(env.IsDevelopment()) {
     app.UseDeveloperExceptionPage();
} 

The application app.UseDeveloperExceptionPage();line causes detailed information to be displayed in the browser when an exception occurs, which is very useful for debugging.

I'm sure you saw the result, it looks something like this:

enter image description here

, , , , . System.Exception Data . , , AppException Exception , , :

 /// <summary>
 /// Application Exception. 
 /// </summary>
 /// <param name="message">Message that can be displayed to a visitor.</param>
 /// <param name="privateMessage">Message for developers to pinpoint the circumstances that caused exception.</param>
 /// <param name="innerException"></param>
    public AppException(string message, string privateMessage, Exception innerException = null) 
        : base(message, innerException) {

        //Placing it in the exception Data collection makes the info available in the debugger
        this.Data["PrivateMessage"] = privateMessage;
    }

, , , PrivateMessage Exception ( AppException) . , , , , .

, ?

+5
2

app.UseDeveloperExceptionPage() app.UseDeveloperExceptionPage() DeveloperExceptionPageMiddleware /. DeveloperExceptionPageMiddleware , . .

+2

DeveloperExceptionPageMiddleware - , 500, . , , .

, : HTML dev ( JSON ).

0

Source: https://habr.com/ru/post/1667919/


All Articles