-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add feature to expose IIS hosting details #50128
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ac30a4a
Add IIISEnvironmentFeature
twsouthwick 53ecd81
Use environment variables
twsouthwick 0195515
fix text
twsouthwick beb62df
fix formatting
twsouthwick 3ea689c
move to applicationinfo.cpp
twsouthwick c401ec5
add to publicapi
twsouthwick 2a69e13
add app pool config path
twsouthwick 1d20bf3
react to api feedback
twsouthwick 8dd3702
use ASPNETCORE_ prefix
twsouthwick 68325c9
Update src/Servers/IIS/IIS/src/Core/IISEnvironmentFeature.cs
twsouthwick 568b674
respond to feedback
twsouthwick a464eb6
Merge remote-tracking branch 'origin/main' into iis_app_feature
twsouthwick 28566c0
add comment
twsouthwick 68be21b
Add tests
twsouthwick c44a5cb
add properties to deployer
twsouthwick 27b94d9
don't use auto
twsouthwick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/ModuleEnvironment.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| #include "ModuleEnvironment.h" | ||
| #include <string> | ||
| #include <sstream> | ||
|
|
||
| // Set in the RegisterModule call IIS uses to initiate the module | ||
| extern DWORD g_dwIISServerVersion; | ||
|
|
||
| static std::wstring GetIISVersion() { | ||
| int major = (int)(g_dwIISServerVersion >> 16); | ||
| int minor = (int)(g_dwIISServerVersion & 0xffff); | ||
|
|
||
| std::wstringstream version; | ||
| version << major << "." << minor; | ||
|
|
||
| return version.str(); | ||
| } | ||
|
|
||
| static std::wstring ToVirtualPath(const std::wstring& configurationPath) { | ||
| int segments = 0; | ||
| size_t position = configurationPath.find('/'); | ||
|
|
||
| // Skip first 4 segments of config path | ||
| while (segments != 3 && position != std::wstring::npos) | ||
| { | ||
| segments++; | ||
| position = configurationPath.find('/', position + 1); | ||
| } | ||
|
|
||
| if (position != std::wstring::npos) | ||
| { | ||
| return configurationPath.substr(position); | ||
| } | ||
|
|
||
| return L"/"; | ||
| } | ||
|
|
||
| void SetApplicationEnvironmentVariables(_In_ IHttpServer &server, _In_ IHttpContext &pHttpContext) { | ||
| SetEnvironmentVariable(L"ASPNETCORE_IIS_VERSION", GetIISVersion().c_str()); | ||
|
|
||
| SetEnvironmentVariable(L"ASPNETCORE_IIS_APP_POOL_ID", server.GetAppPoolName()); | ||
|
|
||
| IHttpServer2* server2; | ||
| if (SUCCEEDED(HttpGetExtendedInterface(&server, &server, &server2))) { | ||
| SetEnvironmentVariable(L"ASPNETCORE_IIS_APP_POOL_CONFIG_FILE", server2->GetAppPoolConfigFile()); | ||
| } | ||
|
|
||
| IHttpSite* site = pHttpContext.GetSite(); | ||
| SetEnvironmentVariable(L"ASPNETCORE_IIS_SITE_NAME", site->GetSiteName()); | ||
| SetEnvironmentVariable(L"ASPNETCORE_IIS_SITE_ID", std::to_wstring(site->GetSiteId()).c_str()); | ||
|
|
||
| IHttpApplication* app = pHttpContext.GetApplication(); | ||
| SetEnvironmentVariable(L"ASPNETCORE_IIS_APP_CONFIG_PATH", app->GetAppConfigPath()); | ||
| SetEnvironmentVariable(L"ASPNETCORE_IIS_APPLICATION_ID", app->GetApplicationId()); | ||
| SetEnvironmentVariable(L"ASPNETCORE_IIS_APPLICATION_VIRTUAL_PATH", ToVirtualPath(app->GetAppConfigPath()).c_str()); | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
src/Servers/IIS/AspNetCoreModuleV2/AspNetCore/ModuleEnvironment.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| #pragma once | ||
twsouthwick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| void SetApplicationEnvironmentVariables(_In_ IHttpServer& server, _In_ IHttpContext& pHttpContext); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using Microsoft.Extensions.Configuration; | ||
|
|
||
| namespace Microsoft.AspNetCore.Server.IIS.Core; | ||
|
|
||
| internal sealed class IISEnvironmentFeature : IIISEnvironmentFeature | ||
| { | ||
| public static bool TryCreate(IConfiguration configuration, [NotNullWhen(true)] out IIISEnvironmentFeature? result) | ||
| { | ||
| var feature = new IISEnvironmentFeature(configuration); | ||
|
|
||
| if (feature.IISVersion is not null) | ||
| { | ||
| result = feature; | ||
| return true; | ||
| } | ||
|
|
||
| result = null; | ||
| return false; | ||
| } | ||
|
|
||
| private IISEnvironmentFeature(IConfiguration configuration) | ||
| { | ||
| if (Version.TryParse(configuration["IIS_VERSION"], out var version)) | ||
| { | ||
| IISVersion = version; | ||
| } | ||
|
|
||
| if (uint.TryParse(configuration["IIS_SITE_ID"], out var siteId)) | ||
| { | ||
| SiteId = siteId; | ||
| } | ||
|
|
||
| AppPoolId = configuration["IIS_APP_POOL_ID"] ?? string.Empty; | ||
| AppPoolConfigFile = configuration["IIS_APP_POOL_CONFIG_FILE"] ?? string.Empty; | ||
| AppConfigPath = configuration["IIS_APP_CONFIG_PATH"] ?? string.Empty; | ||
| ApplicationPhysicalPath = configuration["IIS_PHYSICAL_PATH"] ?? string.Empty; | ||
| ApplicationVirtualPath = configuration["IIS_APPLICATION_VIRTUAL_PATH"] ?? string.Empty; | ||
| ApplicationId = configuration["IIS_APPLICATION_ID"] ?? string.Empty; | ||
| SiteName = configuration["IIS_SITE_NAME"] ?? string.Empty; | ||
| } | ||
|
|
||
| public Version IISVersion { get; } = null!; | ||
twsouthwick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public string AppPoolId { get; } | ||
|
|
||
| public string AppPoolConfigFile { get; } | ||
|
|
||
| public string AppConfigPath { get; } | ||
|
|
||
| public string ApplicationPhysicalPath { get; } | ||
|
|
||
| public string ApplicationVirtualPath { get; } | ||
|
|
||
| public string ApplicationId { get; } | ||
|
|
||
| public string SiteName { get; } | ||
|
|
||
| public uint SiteId { get; } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.AspNetCore.Server.IIS; | ||
|
|
||
| /// <summary> | ||
| /// This feature provides access to IIS application information | ||
| /// </summary> | ||
| public interface IIISEnvironmentFeature | ||
| { | ||
| /// <summary> | ||
| /// Gets the version of IIS that is being used. | ||
| /// </summary> | ||
| Version IISVersion { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the AppPool name that is currently running | ||
| /// </summary> | ||
| string AppPoolId { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the path to the AppPool config | ||
| /// </summary> | ||
| string AppPoolConfigFile { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets path to the application configuration that is currently running | ||
| /// </summary> | ||
| string AppConfigPath { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the physical path of the application. | ||
| /// </summary> | ||
| string ApplicationPhysicalPath { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the virtual path of the application. | ||
| /// </summary> | ||
| string ApplicationVirtualPath { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets ID of the current application. | ||
| /// </summary> | ||
| string ApplicationId { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the name of the current site. | ||
| /// </summary> | ||
| string SiteName { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the id of the current site. | ||
| /// </summary> | ||
| uint SiteId { get; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.