skip to Main Content

I want to use Environment.IsDevelopment() before builder.Build() in Program.cs. How should I do that?

 var builder = WebApplication.CreateBuilder(args);
 //Code: reach environment
 var app = builder.Build();

2

Answers


  1. It may not be what you are looking for, but I have used:

    app.UseDeveloperExceptionPage();
    

    after

    var app = builder.Build();
    

    and before

    app.Run();
    

    This allows for more verbose exception pages in production (had a few issues where errors were thrown in production but not in development).

    Login or Signup to reply.
  2. You can access which environment you are currently running as by using:

    builder.Environment.IsDevelopment()
    

    Prior to the application being built at this point:

    var app = builder.Build();
    

    After this code has run you would use:

    app.Environment.IsDevelopment()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search