Open Closed

ASP.NET Core UseExceptionHandler extension do not work with ABP #1821


User avatar
0
bozkan created
  • ABP Framework version: v4.3.0
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:" Apply method explained on https://docs.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-5.0#exception-handler-lambda

I am trying to globally catch (and modify) any exceptions occured on my ABP project and trying different methods which no one could be successful so far. One of them is using the exception handler lambda explained on https://docs.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-5.0#exception-handler-lambda. Even if I configured the lambda and throw exception in some method, the lambda method is not hit.

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    Can you share your code? thanks.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    bozkan created

    It's just a simple app service method that I throw exception on purpose.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    It works for me.

    public class IndexModel : AbpPageModel
    {
        public void OnGet()
        {
            throw new Exception("test");
        }
    }
    
    app.UseExceptionHandler(x => x.Run(async errorContext =>
    {
        errorContext.Response.StatusCode = (int) HttpStatusCode.InternalServerError;
        errorContext.Response.ContentType = "text/html";
    
        await errorContext.Response.WriteAsync("<html lang=\"en\"><body>\r\n");
        await errorContext.Response.WriteAsync("ERROR!<br><br>\r\n");
    
        var exceptionHandlerPathFeature =
            errorContext.Features.Get<IExceptionHandlerPathFeature>();
    
        if (exceptionHandlerPathFeature?.Error is FileNotFoundException)
        {
            await errorContext.Response.WriteAsync(
                "File error thrown!<br><br>\r\n");
        }
    
        await errorContext.Response.WriteAsync(
            "<a href=\"/\">Home</a><br>\r\n");
        await errorContext.Response.WriteAsync("</body></html>\r\n");
        await errorContext.Response.WriteAsync(new string(' ', 512));
    }));
    

    Could you share a project to reproduce it? shiwei.liang@volosoft.com

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.