You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As highlighted here #47093 (comment), when running an ASP.NET CORE application (.NET 6 and higher) in IIS with "Preload = true" (Application Initialization module), the APP_POOL_ID environment variable is null.
Setting "Preload = false" in IIS everything works fine, the APP_POOL_ID environment variable is correctly set.
This is a significant problem in some scenarios, because the application is not aware of its Application Pool, which is often a discriminator for configurations loading.
In my case, for example, multiple Application Pools and WebSites are sharing/based on the same application folder and files (every web site loads its own configuration based on the name of the Application Pool that hosts it)
I tried waiting for the variable to be populated (since the original post seemed to suggest that this problem is somehow time-related), but it never happens.
varappPoolId= Environment.GetEnvironmentVariable("APP_POOL_ID");
logger.LogInformation("App Pool Id = {AppPoolId}", appPoolId);if(string.IsNullOrWhiteSpace(appPoolId)){do{
logger.LogError("App Pool Id is NOT VALID. This is NOT allowed in {EnvironmentName}", appBuilder.Environment.EnvironmentName);appPoolId= Environment.GetEnvironmentVariable("APP_POOL_ID");if(string.IsNullOrWhiteSpace(appPoolId))// still unresolved ?{// wait a bit, maybe the environment variables will be set correctly
Thread.Sleep(1000);}else{break;// App Pool ID resolved, exit the loop and continue with the application initialization}}while(true);// loop unti a valid App Pool Id is resolved}
I also couldn't find any documentation about this behaviour, or anything related.
Is it a bug in IIS ? In ASP.NET CORE ?
Is there a known workaround, or a proper solution to this problem ?
Any suggestion will be greatly appreciated :)
Expected Behavior
I expect the environment variable APP_POOL_ID to be correctly set, even when "Preload = true" (Application Initialization module)
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
.NET 6 or higher
Anything else?
No response
The text was updated successfully, but these errors were encountered:
NinjaCross
changed the title
APP_POOL_ID environmental variable is null when Preload = True
APP_POOL_ID environment variable is null when Preload = True
Nov 29, 2024
Is there an existing issue for this?
Describe the bug
As highlighted here #47093 (comment), when running an ASP.NET CORE application (.NET 6 and higher) in IIS with "Preload = true" (Application Initialization module), the APP_POOL_ID environment variable is null.
Setting "Preload = false" in IIS everything works fine, the APP_POOL_ID environment variable is correctly set.
This is a significant problem in some scenarios, because the application is not aware of its Application Pool, which is often a discriminator for configurations loading.
In my case, for example, multiple Application Pools and WebSites are sharing/based on the same application folder and files (every web site loads its own configuration based on the name of the Application Pool that hosts it)
I tried waiting for the variable to be populated (since the original post seemed to suggest that this problem is somehow time-related), but it never happens.
I also couldn't find any documentation about this behaviour, or anything related.
Is it a bug in IIS ? In ASP.NET CORE ?
Is there a known workaround, or a proper solution to this problem ?
Any suggestion will be greatly appreciated :)
Expected Behavior
I expect the environment variable APP_POOL_ID to be correctly set, even when "Preload = true" (Application Initialization module)
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
.NET 6 or higher
Anything else?
No response
The text was updated successfully, but these errors were encountered: