locked
How to enable customerrors in ASP.NET Core web application RRS feed

  • Question

  • User2097725413 posted

    Hello,

    I am using ASP.NET core web application, In one of the scenarios, I want to know the exception. But in .Net core application, I am unable to diagnosis the application, As compared to ASP.NET MVC applications, it has Web.Config file and inside that <customErrors mode="On"/>, using customErrors we can able to diagnosis the error but in .net core application Startup.cs file it doesn't have "customErrors".

    In .net core application, whenever any exceptions come, it is displaying the common error as below,

    Error.
    An error occurred while processing your request.
    Request ID: |effe4848-4d1bd47df96d841d.

    Development Mode
    Swapping to Development environment will display more detailed information about the error that occurred.

    Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.

    Because of common error, I am not able to diagnose the actual error/exception to find out the cause.

    Can anyone please let me know, how to enable customErrors similar ASP.NET MVC to ASP.NET Core application.

    Thanks,
    Uday Mahajan

    Sunday, September 27, 2020 12:33 PM

All replies

  • User-474980206 posted

    In startup just add a configuration of you choice to control the developer page option

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

    Sunday, September 27, 2020 3:41 PM
  • User2097725413 posted

    Hi Bruce,

    Thanks for your quick reply.

    I would like to understand in details  regarding the implementation of "myoption"

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

    Could you please provide me a sample of code to implement "myoption".

    Thanks,

    Uday Mahajan


    Sunday, September 27, 2020 4:55 PM
  • User-474980206 posted

    Configuration setting would be a good choice.

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1

    Sunday, September 27, 2020 9:47 PM