I have a .Net 6 web app and I am developing the app in Visual Studio 2022 on my local machine.
I don't want certain things to run when I'm developing so I am trying to use env.IsDevelopment()
to catch when I am running the app in Visual Studio instead of my external IIS server.
So I have this below:
public void Configure(IApplicationBuilder app, IBackgroundJobClient backgroundJobs, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
} else {
// in production
And I set a breakpoint in VS on this line if (env.IsDevelopment())
.
When I step through the app in VS, it hits that line, but then skips over to the // in production
part
How do I let the app know it's in development?
Thanks!
CodePudding user response:
If you are development the application inside the visual studio, you could modify the launchSettings.json file inside your project.
Inside the environmentVariables, you could modify it to development or production.
Please notice: The IIS express is running inside the IIS express, the another one is running as the exe for your application.
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59481",
"sslPort": 44308
}
},
"profiles": {
"EnvironmentsSample": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7152;http://localhost:5105",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
After you deploy the application to the server, there is multiple way to set the environment variable, like set windows environment variable or set inside the web.config if you host it at the IIS.
More details about how to do it, you could refer to this article.