question

KUNALGUPTA-8545 avatar image
0 Votes"
KUNALGUPTA-8545 asked KUNALGUPTA-8545 answered

Developer Exception Page

I am new to ASP.NET Core and don't know much. I am using app.UseDeveloperExceptionPage() but still not able to see developer exception page. I am using windows OS. I have upload the project to Github. Here is the URL - https://github.com/gupta6/ConsoleToApI1 .

Below is my code.

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;

namespace ConsoleToApI1
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}

     public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
     {
         app.UseRouting();

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

         app.UseEndpoints(endpoints =>
         {
             endpoints.MapControllers();
         });
     }
 }

}

dotnet-csharpwindows-server-iisdotnet-aspnet-core-webapi
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

How did you trigger the exception? You'd better share the complete project somewhere so that others might tell you what's wrong. Merely the code snippet you shared does not help.

0 Votes 0 ·

Yes, you are right it's difficult to find without complete code. I have uploaded my project to Github. Here is the URL of the repository - https://github.com/gupta6/ConsoleToApI1

0 Votes 0 ·
KUNALGUPTA-8545 avatar image
0 Votes"
KUNALGUPTA-8545 answered

Hello, thanks to all for taking time to answer the question. But I have found the solution. There is a problem in the order of the execution in the startup file. I have first use routing and then check for development mode and this is wrong. The correct order for this is to first check the development mode and then use routing.125213-capture.png



capture.png (81.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ZhiLv-MSFT avatar image
0 Votes"
ZhiLv-MSFT answered KUNALGUPTA-8545 commented

Hi @KUNALGUPTA-8545,

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

From the above code, we can know that the Developer Exception Page only when the app runs in the Development environment. So, please check the application environment setting, make sure it is in the Development environment.

I assume you are launching the application using IIS express, if that is the case, please open application's launchSettings.json file, and make sure you are setting the ASPNETCORE_ENVIRONMENT to Development, check the following screenshot:

125185-image.png

More detail information about setting environment, see Use multiple environments in ASP.NET Core.

Besides, you can also set a break point at the app.UseDeveloperExceptionPage(); line, then in the debug mode, checks whether this method is executed or not. If this method is executed, the issue might relate your code, please check your code where throws the exception and is there have any exception handling page.


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Best regards,
Dillion



image.png (102.0 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for answering. But I have already done what you are saying and still I am not able to see developer exception page. And I have set break point and the method is executing.

0 Votes 0 ·