Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APP_POOL_ID environment variable is null when Preload = True #59213

Open
1 task done
NinjaCross opened this issue Nov 28, 2024 · 0 comments
Open
1 task done

APP_POOL_ID environment variable is null when Preload = True #59213

NinjaCross opened this issue Nov 28, 2024 · 0 comments
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Comments

@NinjaCross
Copy link

NinjaCross commented Nov 28, 2024

Is there an existing issue for this?

  • I have searched the existing issues

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.

var appPoolId = 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

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Nov 28, 2024
@NinjaCross 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

No branches or pull requests

1 participant