├── src ├── Microsoft.AspNetCore.Server.IIS │ ├── _._ │ ├── Core │ │ ├── HttpStreamState.cs │ │ ├── IO │ │ │ ├── IAsyncIOEngine.cs │ │ │ ├── AsyncIOEngine.Write.cs │ │ │ ├── AsyncIOEngine.Flush.cs │ │ │ └── WebSocketsAsyncIOEngine.Initialize.cs │ │ ├── IISConfigurationData.cs │ │ ├── ThrowingWasUpgradedWriteOnlyStream.cs │ │ ├── IISServerSetupFilter.cs │ │ ├── IISHttpContext.IHttpRequestIdentifierFeature.cs │ │ └── WriteOnlyStream.cs │ ├── IISServerDefaults.cs │ ├── Microsoft.AspNetCore.Server.IIS.targets │ ├── AssemblyInfo.cs │ ├── IServerVariableFeature.cs │ ├── IISServerOptions.cs │ └── HttpContextExtensions.cs ├── AspNetCoreModuleV1 │ ├── AspNetCore │ │ ├── Source.def │ │ ├── resource.h │ │ ├── src │ │ │ ├── protocolconfig.cxx │ │ │ └── forwarderconnection.cxx │ │ ├── Inc │ │ │ ├── proxymodule.h │ │ │ └── debugutil.h │ │ └── aspnetcore_msg.mc │ └── IISLib │ │ ├── datetime.h │ │ ├── precomp.h │ │ ├── ntassert.h │ │ ├── base64.h │ │ └── macros.h ├── AspNetCoreModuleV2 │ ├── AspNetCore │ │ ├── Source.def │ │ ├── HtmlResponses.rc │ │ ├── stdafx.cpp │ │ ├── resource.h │ │ ├── stdafx.h │ │ ├── AppOfflineHandler.h │ │ ├── AppOfflineApplication.h │ │ ├── globalmodule.h │ │ ├── AppOfflineHandler.cpp │ │ ├── DisconnectHandler.h │ │ ├── DisconnectHandler.cpp │ │ ├── applicationmanager.h │ │ ├── ServerErrorApplication.h │ │ ├── PollingAppOfflineApplication.h │ │ └── HandlerResolver.h │ ├── InProcessRequestHandler │ │ ├── Source.def │ │ ├── HtmlResponses.rc │ │ ├── stdafx.cpp │ │ ├── resource.h │ │ ├── InProcessApplicationBase.h │ │ ├── StartupExceptionHandler.h │ │ ├── StartupExceptionApplication.h │ │ ├── ShuttingDownApplication.h │ │ └── InProcessApplicationBase.cpp │ ├── OutOfProcessRequestHandler │ │ ├── Source.def │ │ ├── stdafx.cpp │ │ ├── resource.h │ │ ├── url_utility.h │ │ ├── protocolconfig.cpp │ │ ├── forwarderconnection.cpp │ │ ├── outprocessapplication.h │ │ └── HtmlResponses.rc │ ├── CommonLib │ │ ├── stdafx.cpp │ │ ├── targetver.h │ │ ├── NonCopyable.h │ │ ├── SRWSharedLock.h │ │ ├── SRWExclusiveLock.h │ │ ├── SRWSharedLock.cpp │ │ ├── SRWExclusiveLock.cpp │ │ ├── stdafx.h │ │ ├── HandleWrapper.cpp │ │ ├── IOutputManager.h │ │ ├── Environment.h │ │ ├── LoggingHelpers.h │ │ ├── ResultException.h │ │ ├── NullOutputManager.h │ │ ├── ConfigurationLoadException.h │ │ ├── InvalidOperationException.h │ │ ├── ConfigurationSource.cpp │ │ ├── StdWrapper.h │ │ ├── WebConfigConfigurationSource.h │ │ ├── WebConfigConfigurationSource.cpp │ │ ├── file_utility.h │ │ ├── GlobalVersionUtility.h │ │ ├── EventTracing.h │ │ ├── WebConfigConfigurationSection.h │ │ ├── FileOutputManager.h │ │ ├── ConfigurationSource.h │ │ ├── ModuleHelpers.h │ │ ├── PipeOutputManager.h │ │ ├── irequesthandler.h │ │ ├── StringHelpers.cpp │ │ ├── StringHelpers.h │ │ ├── fx_ver.h │ │ └── LoggingHelpers.cpp │ ├── IISLib │ │ ├── datetime.h │ │ ├── precomp.h │ │ ├── ntassert.h │ │ ├── base64.h │ │ └── macros.h │ └── RequestHandlerLib │ │ ├── stdafx.h │ │ ├── AppOfflineTrackingApplication.h │ │ └── filewatcher.h ├── Directory.Build.props ├── Microsoft.AspNetCore.Server.IISIntegration │ ├── Microsoft.AspNetCore.Server.IISIntegration.targets │ ├── IISDefaults.cs │ ├── NativeMethods.cs │ ├── IISHostingStartup.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── IISSetupFilter.cs │ └── IISOptions.cs └── Microsoft.AspNetCore.Server.IntegrationTesting.IIS │ ├── WebConfigHelpers.cs │ ├── IISDeploymentResult.cs │ └── XElementExtensions.cs ├── test ├── WebSites │ ├── InProcessWebSite │ │ ├── wwwroot │ │ │ └── static.txt │ │ ├── DummyServer.cs │ │ ├── web.config │ │ ├── Properties │ │ │ └── launchSettings.json │ │ └── InProcessWebSite.csproj │ ├── OutOfProcessWebSite │ │ ├── wwwroot │ │ │ └── static.txt │ │ ├── Program.cs │ │ ├── OutOfProcessWebSite.csproj │ │ └── Properties │ │ │ └── launchSettings.json │ ├── Directory.Build.props │ ├── shared │ │ └── WebSockets │ │ │ ├── Constants.cs │ │ │ └── TestStartup.cs │ ├── StressTestWebSite │ │ ├── Program.cs │ │ ├── StressTestWebSite.csproj │ │ └── Properties │ │ │ └── launchSettings.json │ └── InProcessForwardsCompatWebSite │ │ └── Properties │ │ └── launchSettings.json ├── CommonLibTests │ ├── NativeTests.targets │ ├── main.cpp │ ├── Helpers.h │ ├── exception_handler_tests.cpp │ ├── Helpers.cpp │ └── stdafx.h ├── TestTasks │ └── TestTasks.csproj ├── IIS.Shared.FunctionalTests │ ├── Properties │ │ └── AssemblyInfo.cs │ └── MofFileTests.cs ├── IISExpress.FunctionalTests │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── DeployerSelector.cs │ └── RequiresIISAttribute.cs ├── Common.FunctionalTests │ ├── Utilities │ │ ├── IISCompressionSiteCollection.cs │ │ ├── IISFunctionalTestBase.cs │ │ ├── IISCapability.cs │ │ ├── SkipIfDebugAttribute.cs │ │ ├── RequiresEnvironmentVariableAttribute.cs │ │ ├── IISTestSiteCollection.cs │ │ ├── LogFileTestBase.cs │ │ └── IISCompressionSiteFixture.cs │ ├── RequiresNewShim.cs │ ├── RequiresNewHandler.cs │ ├── SkipVSTSAttribute.cs │ ├── SkipIfNotAdminAttribute.cs │ ├── Inprocess │ │ ├── FixtureLoggedTest.cs │ │ ├── HelloWorldTests.cs │ │ ├── FeatureCollectionTests.cs │ │ ├── ResponseInvalidOrderingTests.cs │ │ ├── LargeResponseBodyTests.cs │ │ ├── HostingEnvironmentTests.cs │ │ └── EventLogTests.cs │ └── CommonStartupTests.cs ├── IIS.FunctionalTests │ └── DeployerSelector.cs ├── IIS.ForwardsCompatibility.FunctionalTests │ ├── DeployerSelector.cs │ └── ForwardsCompatibilityTests.cs ├── IIS.BackwardsCompatibility.FunctionalTests │ ├── DeployerSelector.cs │ └── BackwardsCompatibilityTests.cs ├── Common.Tests │ ├── Utilities │ │ ├── DisposableList.cs │ │ └── TimeoutExtensions.cs │ └── Common.Tests.csproj ├── IIS.Tests │ ├── Utilities │ │ └── SkipIfHostableWebCoreNotAvailibleAttribute.cs │ ├── StrictTestServerTests.cs │ ├── HttpBodyControlFeatureTests.cs │ └── TestServerTest.cs ├── Microsoft.AspNetCore.Server.IISIntegration.Tests │ ├── Microsoft.AspNetCore.Server.IISIntegration.Tests.csproj │ └── IISExtensionTests.cs └── Directory.Build.props ├── tools ├── httpsys.ps1 ├── certificate.ps1 └── UpdateIISExpressCertificate.ps1 ├── korebuild-lock.txt ├── .gitmodules ├── NuGetPackageVerifier.xplat.json ├── CONTRIBUTING.md ├── NuGet.config ├── run.cmd ├── .vsts-pipelines └── builds │ ├── ci-internal.yml │ ├── ci-public.yml │ └── ci-internal-21.yml ├── NuGetPackageVerifier.json ├── nuget ├── Microsoft.AspNetCore.AspNetCoreModule.props └── Microsoft.AspNetCore.AspNetCoreModuleV2.props.in ├── samples ├── NativeIISSample │ ├── web.config │ ├── NativeIISSample.csproj │ └── Properties │ │ └── launchSettings.json └── IISSample │ ├── IISSample.csproj │ ├── Properties │ └── launchSettings.json │ └── web.config ├── .editorconfig ├── korebuild.json ├── Directory.Build.targets ├── .appveyor.yml ├── .gitattributes ├── README.md ├── Directory.Build.props ├── .gitignore ├── benchmarks └── IIS.Performance │ └── FirstRequestConfig.cs └── version.props /src/Microsoft.AspNetCore.Server.IIS/_._: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/WebSites/InProcessWebSite/wwwroot/static.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/WebSites/OutOfProcessWebSite/wwwroot/static.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/httpsys.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/IISIntegration/HEAD/tools/httpsys.ps1 -------------------------------------------------------------------------------- /tools/certificate.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/IISIntegration/HEAD/tools/certificate.ps1 -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/AspNetCore/Source.def: -------------------------------------------------------------------------------- 1 | LIBRARY aspnetcore 2 | 3 | EXPORTS 4 | RegisterModule 5 | -------------------------------------------------------------------------------- /korebuild-lock.txt: -------------------------------------------------------------------------------- 1 | version:3.0.0-alpha1-20181011.11 2 | commithash:f57aa8ddda0abdd74ada55853587bedb4f364065 3 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/Source.def: -------------------------------------------------------------------------------- 1 | LIBRARY aspnetcorev2 2 | 3 | EXPORTS 4 | RegisterModule 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "test/gtest/googletest"] 2 | path = test/gtest/googletest 3 | url = https://github.com/google/googletest 4 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/InProcessRequestHandler/Source.def: -------------------------------------------------------------------------------- 1 | LIBRARY aspnetcorev2_inprocess 2 | 3 | EXPORTS 4 | CreateApplication 5 | 6 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/OutOfProcessRequestHandler/Source.def: -------------------------------------------------------------------------------- 1 | LIBRARY aspnetcorev2_outofprocess 2 | 3 | EXPORTS 4 | CreateApplication 5 | 6 | -------------------------------------------------------------------------------- /NuGetPackageVerifier.xplat.json: -------------------------------------------------------------------------------- 1 | { 2 | "Default": { 3 | "rules": [ 4 | "DefaultCompositeRule" 5 | ] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/HtmlResponses.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/IISIntegration/HEAD/src/AspNetCoreModuleV2/AspNetCore/HtmlResponses.rc -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/InProcessRequestHandler/HtmlResponses.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/IISIntegration/HEAD/src/AspNetCoreModuleV2/InProcessRequestHandler/HtmlResponses.rc -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ====== 3 | 4 | Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/master/CONTRIBUTING.md) in the Home repo. 5 | -------------------------------------------------------------------------------- /test/WebSites/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /NuGet.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /run.cmd: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' %*; exit $LASTEXITCODE" 3 | -------------------------------------------------------------------------------- /src/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | // Do not remove this file. It is used for precompiled header generation 5 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | // Do not remove this file. It is used for precompiled header generation 5 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/InProcessRequestHandler/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | // Do not remove this file. It is used for precompiled header generation 5 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/OutOfProcessRequestHandler/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | // Do not remove this file. It is used for precompiled header generation 5 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IISIntegration/Microsoft.AspNetCore.Server.IISIntegration.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AspNetCoreModuleV2 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.vsts-pipelines/builds/ci-internal.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | - master 3 | - release/* 4 | 5 | resources: 6 | repositories: 7 | - repository: buildtools 8 | type: git 9 | name: aspnet-BuildTools 10 | ref: refs/heads/master 11 | 12 | phases: 13 | - template: ../templates/build-steps.yml 14 | -------------------------------------------------------------------------------- /test/CommonLibTests/NativeTests.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(VCIDEInstallDir)..\CommonExtensions\Microsoft\TestWindow\vstest.console.exe 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include -------------------------------------------------------------------------------- /NuGetPackageVerifier.json: -------------------------------------------------------------------------------- 1 | { 2 | "adx-nonshipping": { 3 | "rules": [], 4 | "packages": { 5 | "Microsoft.AspNetCore.AspNetCoreModule": {}, 6 | "Microsoft.AspNetCore.AspNetCoreModuleV2": {} 7 | } 8 | }, 9 | "Default": { 10 | "rules": [ 11 | "DefaultCompositeRule" 12 | ] 13 | } 14 | } -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/IISLib/datetime.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #ifndef _DATETIME_H_ 5 | #define _DATETIME_H_ 6 | 7 | BOOL 8 | StringTimeToFileTime( 9 | PCSTR pszTime, 10 | ULONGLONG * pulTime 11 | ); 12 | 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/IISLib/datetime.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #ifndef _DATETIME_H_ 5 | #define _DATETIME_H_ 6 | 7 | BOOL 8 | StringTimeToFileTime( 9 | PCSTR pszTime, 10 | ULONGLONG * pulTime 11 | ); 12 | 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /test/TestTasks/TestTasks.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | $(StandardTestTfms) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.vsts-pipelines/builds/ci-public.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | - master 3 | - release/* 4 | 5 | # See https://github.com/aspnet/BuildTools 6 | resources: 7 | repositories: 8 | - repository: buildtools 9 | type: github 10 | endpoint: DotNet-Bot GitHub Connection 11 | name: aspnet/BuildTools 12 | ref: refs/heads/master 13 | 14 | phases: 15 | - template: ../templates/build-steps.yml 16 | -------------------------------------------------------------------------------- /nuget/Microsoft.AspNetCore.AspNetCoreModule.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildThisFileDirectory)..\contentFiles\any\any\x64\aspnetcore.dll 5 | $(MSBuildThisFileDirectory)..\contentFiles\any\any\x86\aspnetcore.dll 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/Core/HttpStreamState.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.AspNetCore.Server.IIS.Core 5 | { 6 | enum HttpStreamState 7 | { 8 | Open, 9 | Closed, 10 | Aborted 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/NonCopyable.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | class NonCopyable { 7 | public: 8 | NonCopyable() = default; 9 | NonCopyable(const NonCopyable&) = delete; 10 | NonCopyable& operator=(const NonCopyable&) = delete; 11 | }; 12 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/IISServerDefaults.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.AspNetCore.Server.IIS 5 | { 6 | public class IISServerDefaults 7 | { 8 | public const string AuthenticationScheme = "Windows"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/SRWSharedLock.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | class SRWSharedLock 9 | { 10 | public: 11 | SRWSharedLock(const SRWLOCK& lock); 12 | ~SRWSharedLock(); 13 | private: 14 | const SRWLOCK& m_lock; 15 | }; 16 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/SRWExclusiveLock.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | class SRWExclusiveLock 9 | { 10 | public: 11 | SRWExclusiveLock(const SRWLOCK& lock) noexcept; 12 | ~SRWExclusiveLock(); 13 | private: 14 | const SRWLOCK& m_lock; 15 | }; 16 | -------------------------------------------------------------------------------- /samples/NativeIISSample/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/CommonLibTests/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #include "stdafx.h" 5 | 6 | DECLARE_DEBUG_PRINT_OBJECT2("tests", ASPNETCORE_DEBUG_FLAG_INFO | ASPNETCORE_DEBUG_FLAG_CONSOLE); 7 | 8 | int wmain(int argc, wchar_t* argv[]) 9 | { 10 | ::testing::InitGoogleTest(&argc, argv); 11 | RUN_ALL_TESTS(); 12 | } 13 | -------------------------------------------------------------------------------- /test/IIS.Shared.FunctionalTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests; 5 | using Microsoft.Extensions.Logging.Testing; 6 | using Xunit; 7 | 8 | [assembly: CollectionBehavior(DisableTestParallelization = true)] 9 | [assembly: RequiresIIS] 10 | [assembly: ShortClassName] 11 | -------------------------------------------------------------------------------- /test/IISExpress.FunctionalTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests; 5 | using Microsoft.Extensions.Logging.Testing; 6 | using Xunit; 7 | 8 | [assembly: CollectionBehavior(DisableTestParallelization = true)] 9 | [assembly: RequiresIIS] 10 | [assembly: ShortClassName] 11 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/Microsoft.AspNetCore.Server.IIS.targets: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | AspNetCoreModuleV2 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/SRWSharedLock.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include "SRWSharedLock.h" 5 | 6 | SRWSharedLock::SRWSharedLock(const SRWLOCK& lock) 7 | : m_lock(lock) 8 | { 9 | AcquireSRWLockShared(const_cast(&m_lock)); 10 | } 11 | 12 | SRWSharedLock::~SRWSharedLock() 13 | { 14 | ReleaseSRWLockShared(const_cast(&m_lock)); 15 | } 16 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome:http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | indent_style = space 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.cs] 13 | indent_size = 4 14 | dotnet_sort_system_directives_first = true:warning 15 | 16 | # Xml files 17 | [*.{csproj,config,props,targets,ruleset,config,resx,xml}] 18 | indent_size = 2 19 | 20 | [*.{json, yml}] 21 | indent_size = 2 22 | 23 | [*.{ps1,sh}] 24 | indent_size = 4 25 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IISIntegration/IISDefaults.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.AspNetCore.Server.IISIntegration 5 | { 6 | public class IISDefaults 7 | { 8 | public static readonly string AuthenticationScheme = "Windows"; 9 | public const string Negotiate = "Negotiate"; 10 | public const string Ntlm = "NTLM"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/SRWExclusiveLock.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include "SRWExclusiveLock.h" 5 | 6 | SRWExclusiveLock::SRWExclusiveLock(const SRWLOCK& lock) noexcept 7 | : m_lock(lock) 8 | { 9 | AcquireSRWLockExclusive(const_cast(&m_lock)); 10 | } 11 | 12 | SRWExclusiveLock::~SRWExclusiveLock() 13 | { 14 | ReleaseSRWLockExclusive(const_cast(&m_lock)); 15 | } 16 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/stdafx.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "targetver.h" 7 | 8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/HandleWrapper.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #include "HandleWrapper.h" 5 | 6 | // Workaround for VC++ bug https://developercommunity.visualstudio.com/content/problem/33928/constexpr-failing-on-nullptr-v141-compiler-regress.html 7 | const HANDLE InvalidHandleTraits::DefaultHandle = INVALID_HANDLE_VALUE; 8 | const HANDLE FindFileHandleTraits::DefaultHandle = INVALID_HANDLE_VALUE; 9 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/InProcessRequestHandler/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by HtmlResponses.rc 4 | // 5 | #define IN_PROCESS_RH_STATIC_HTML 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/OutOfProcessRequestHandler/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by HtmlResponses.rc 4 | // 5 | #define OUT_OF_PROCESS_RH_STATIC_HTML 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Utilities/IISCompressionSiteCollection.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Xunit; 5 | 6 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 7 | { 8 | [CollectionDefinition(Name)] 9 | public class IISCompressionSiteCollection : ICollectionFixture 10 | { 11 | public const string Name = nameof(IISCompressionSiteCollection); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/IOutputManager.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "stdafx.h" 7 | #include "stringa.h" 8 | 9 | class IOutputManager 10 | { 11 | public: 12 | virtual 13 | void 14 | Start() = 0; 15 | 16 | virtual 17 | ~IOutputManager() = default; 18 | 19 | virtual 20 | std::wstring 21 | GetStdOutContent() = 0; 22 | 23 | virtual 24 | void 25 | Stop() = 0; 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/Environment.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | class Environment 10 | { 11 | public: 12 | Environment() = delete; 13 | ~Environment() = delete; 14 | 15 | static 16 | std::wstring ExpandEnvironmentVariables(const std::wstring & str); 17 | static 18 | std::optional GetEnvironmentVariableValue(const std::wstring & str); 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Utilities/IISFunctionalTestBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Server.IntegrationTesting; 5 | using Xunit.Abstractions; 6 | 7 | namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities 8 | { 9 | public class IISFunctionalTestBase : FunctionalTestsBase 10 | { 11 | public IISFunctionalTestBase(ITestOutputHelper output = null) : base(output) 12 | { 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/CommonLibTests/Helpers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | class Helpers 6 | { 7 | public: 8 | static 9 | std::wstring 10 | ReadFileContent(std::wstring file); 11 | }; 12 | 13 | class TempDirectory 14 | { 15 | public: 16 | 17 | TempDirectory(); 18 | 19 | ~TempDirectory(); 20 | 21 | std::filesystem::path path() const 22 | { 23 | return m_path; 24 | } 25 | 26 | private: 27 | std::filesystem::path m_path; 28 | }; 29 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/LoggingHelpers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "BaseOutputManager.h" 7 | 8 | class LoggingHelpers 9 | { 10 | public: 11 | 12 | static 13 | HRESULT 14 | CreateLoggingProvider( 15 | bool fLoggingEnabled, 16 | bool fEnableNativeLogging, 17 | PCWSTR pwzStdOutFileName, 18 | PCWSTR pwzApplicationPath, 19 | std::unique_ptr& outputManager 20 | ); 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/ResultException.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | class ResultException: public std::runtime_error 7 | { 8 | public: 9 | ResultException(HRESULT hr, LOCATION_ARGUMENTS_ONLY) : 10 | runtime_error(format("HRESULT 0x%x returned at " LOCATION_FORMAT, hr, LOCATION_CALL_ONLY)), 11 | m_hr(hr) 12 | { 13 | } 14 | 15 | HRESULT GetResult() const noexcept { return m_hr; } 16 | 17 | private: 18 | HRESULT m_hr; 19 | }; 20 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/NullOutputManager.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "stdafx.h" 7 | 8 | class NullOutputManager : public BaseOutputManager 9 | { 10 | public: 11 | 12 | NullOutputManager() = default; 13 | 14 | ~NullOutputManager() = default; 15 | 16 | void Start() 17 | { 18 | } 19 | 20 | void Stop() 21 | { 22 | } 23 | 24 | std::wstring GetStdOutContent() 25 | { 26 | return L""; 27 | } 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /test/IIS.FunctionalTests/DeployerSelector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Server.IntegrationTesting; 5 | 6 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 7 | { 8 | public static class DeployerSelector 9 | { 10 | public static ServerType ServerType => ServerType.IIS; 11 | public static bool IsBackwardsCompatiblityTest => false; 12 | public static bool IsForwardsCompatibilityTest => false; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/AspNetCore/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by aspnetcoremodule.rc 4 | // 5 | #define ASPNETCORE_EVENT_MSG_BUFFER_SIZE 256 6 | #define IDS_INVALID_PROPERTY 1000 7 | #define IDS_SERVER_ERROR 1001 8 | 9 | // Next default values for new objects 10 | // 11 | #ifdef APSTUDIO_INVOKED 12 | #ifndef APSTUDIO_READONLY_SYMBOLS 13 | #define _APS_NEXT_RESOURCE_VALUE 101 14 | #define _APS_NEXT_COMMAND_VALUE 40001 15 | #define _APS_NEXT_CONTROL_VALUE 1000 16 | #define _APS_NEXT_SYMED_VALUE 101 17 | #endif 18 | #endif 19 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/IISLib/precomp.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include 5 | #include 6 | #pragma warning( disable:4127 ) 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "macros.h" 15 | #include "stringu.h" 16 | #include "stringa.h" 17 | #include "dbgutil.h" 18 | #include "ntassert.h" 19 | #include "ahutil.h" 20 | #include "acache.h" 21 | //#include "base64.hxx" 22 | 23 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by HtmlResponses.rc 4 | // 5 | #define IN_PROCESS_SHIM_STATIC_HTML 101 6 | #define OUT_OF_PROCESS_SHIM_STATIC_HTML 102 7 | #define UNKNOWN_HOSTING_STATIC_HTML 103 8 | 9 | 10 | // Next default values for new objects 11 | // 12 | #ifdef APSTUDIO_INVOKED 13 | #ifndef APSTUDIO_READONLY_SYMBOLS 14 | #define _APS_NEXT_RESOURCE_VALUE 104 15 | #define _APS_NEXT_COMMAND_VALUE 40001 16 | #define _APS_NEXT_CONTROL_VALUE 1001 17 | #define _APS_NEXT_SYMED_VALUE 101 18 | #endif 19 | #endif 20 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/IISLib/precomp.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include 5 | #include 6 | #pragma warning( disable:4127 ) 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "macros.h" 15 | #include "stringu.h" 16 | #include "stringa.h" 17 | #include "dbgutil.h" 18 | #include "ntassert.h" 19 | #include "ahutil.h" 20 | #include "acache.h" 21 | //#include "base64.hxx" 22 | 23 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IISIntegration/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace Microsoft.AspNetCore.Server.IISIntegration 8 | { 9 | internal static class NativeMethods 10 | { 11 | private const string KERNEL32 = "kernel32.dll"; 12 | 13 | [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] 14 | 15 | public static extern bool CloseHandle(IntPtr handle); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/IISExpress.FunctionalTests/DeployerSelector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Server.IntegrationTesting; 5 | 6 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 7 | { 8 | public static class DeployerSelector 9 | { 10 | public static ServerType ServerType => ServerType.IISExpress; 11 | public static bool IsBackwardsCompatiblityTest => false; 12 | public static bool IsForwardsCompatibilityTest => false; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/stdafx.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | #pragma warning( disable : 4091) 6 | 7 | // 8 | // System related headers 9 | // 10 | #define WIN32_LEAN_AND_MEAN 11 | 12 | #define NTDDI_VERSION NTDDI_WIN7 13 | #define WINVER _WIN32_WINNT_WIN7 14 | #define _WIN32_WINNT 0x0601 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "stringu.h" 21 | #include "stringa.h" 22 | 23 | #pragma warning( error : 4091) 24 | -------------------------------------------------------------------------------- /test/IIS.ForwardsCompatibility.FunctionalTests/DeployerSelector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Server.IntegrationTesting; 5 | 6 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 7 | { 8 | public static class DeployerSelector 9 | { 10 | public static ServerType ServerType => ServerType.IIS; 11 | public static bool IsBackwardsCompatiblityTest => false; 12 | public static bool IsForwardsCompatibilityTest => true; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/IIS.BackwardsCompatibility.FunctionalTests/DeployerSelector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Server.IntegrationTesting; 5 | 6 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 7 | { 8 | public static class DeployerSelector 9 | { 10 | public static ServerType ServerType => ServerType.IIS; 11 | public static bool IsBackwardsCompatiblityTest => true; 12 | public static bool IsForwardsCompatibilityTest => false; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IISIntegration/IISHostingStartup.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Hosting; 5 | 6 | [assembly: HostingStartup(typeof(Microsoft.AspNetCore.Server.IISIntegration.IISHostingStartup))] 7 | 8 | namespace Microsoft.AspNetCore.Server.IISIntegration 9 | { 10 | public class IISHostingStartup : IHostingStartup 11 | { 12 | public void Configure(IWebHostBuilder builder) 13 | { 14 | builder.UseIISIntegration(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /korebuild.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/master/tools/korebuild.schema.json", 3 | "channel": "master", 4 | "toolsets": { 5 | "visualstudio": { 6 | "required": ["Windows"], 7 | "includePrerelease": true, 8 | "minVersion": "15.0.26730.03", 9 | "requiredWorkloads": [ 10 | "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", 11 | "Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81", 12 | "Microsoft.VisualStudio.Component.VC.ATL", 13 | "Microsoft.VisualStudio.Component.Windows10SDK.15063.Desktop" 14 | ] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/ConfigurationLoadException.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | class ConfigurationLoadException: public std::runtime_error 9 | { 10 | public: 11 | ConfigurationLoadException(std::wstring msg) 12 | : runtime_error("Configuration load exception has occured"), message(std::move(msg)) 13 | { 14 | } 15 | 16 | std::wstring get_message() const { return message; } 17 | 18 | private: 19 | std::wstring message; 20 | }; 21 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Runtime.CompilerServices; 5 | 6 | [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.IISIntegration.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] 7 | 8 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/Core/IO/IAsyncIOEngine.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Buffers; 6 | using System.Threading.Tasks; 7 | 8 | namespace Microsoft.AspNetCore.Server.IIS.Core.IO 9 | { 10 | internal interface IAsyncIOEngine: IDisposable 11 | { 12 | ValueTask ReadAsync(Memory memory); 13 | ValueTask WriteAsync(ReadOnlySequence data); 14 | ValueTask FlushAsync(); 15 | void NotifyCompletion(int hr, int bytes); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/InvalidOperationException.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | #include 6 | 7 | class InvalidOperationException: public std::runtime_error 8 | { 9 | public: 10 | InvalidOperationException(std::wstring msg) 11 | : runtime_error("InvalidOperationException"), message(std::move(msg)) 12 | { 13 | } 14 | 15 | std::wstring as_wstring() const 16 | { 17 | return message; 18 | } 19 | 20 | private: 21 | std::wstring message; 22 | }; 23 | -------------------------------------------------------------------------------- /samples/IISSample/IISSample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2;net461 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IISIntegration/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Runtime.CompilerServices; 5 | 6 | [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.IISIntegration.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] 7 | 8 | -------------------------------------------------------------------------------- /Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(MicrosoftNETCoreApp21PackageVersion) 4 | $(MicrosoftNETCoreApp22PackageVersion) 5 | $(NETStandardLibrary20PackageVersion) 6 | 7 | 99.9 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/OutOfProcessRequestHandler/url_utility.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "stdafx.h" 7 | 8 | #include 9 | #include "stringu.h" 10 | 11 | class URL_UTILITY 12 | { 13 | public: 14 | 15 | static 16 | HRESULT 17 | SplitUrl( 18 | PCWSTR pszDestinationUrl, 19 | BOOL *pfSecure, 20 | STRU *pstrDestination, 21 | STRU *pstrUrl 22 | ); 23 | 24 | static HRESULT 25 | EscapeAbsPath( 26 | IHttpRequest * pRequest, 27 | STRU * strEscapedUrl 28 | ); 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/ConfigurationSource.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include "ConfigurationSource.h" 5 | 6 | #include "StringHelpers.h" 7 | #include "ConfigurationLoadException.h" 8 | 9 | std::shared_ptr ConfigurationSource::GetRequiredSection(const std::wstring& name) const 10 | { 11 | auto section = GetSection(name); 12 | if (!section) 13 | { 14 | throw ConfigurationLoadException(format(L"Unable to get required configuration section '%s'. Possible reason is web.config authoring error.", name.c_str())); 15 | } 16 | return section; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/RequestHandlerLib/stdafx.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "Shlwapi.h" 18 | #include 19 | 20 | #include "hashtable.h" 21 | #include "stringu.h" 22 | #include "stringa.h" 23 | #include "multisz.h" 24 | #include "dbgutil.h" 25 | #include "ahutil.h" 26 | #include "hashfn.h" 27 | -------------------------------------------------------------------------------- /test/WebSites/shared/WebSockets/Constants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests 5 | { 6 | public static class Constants 7 | { 8 | public static class Headers 9 | { 10 | public const string Upgrade = "Upgrade"; 11 | public const string UpgradeWebSocket = "websocket"; 12 | public const string Connection = "Connection"; 13 | public const string SecWebSocketKey = "Sec-WebSocket-Key"; 14 | public const string SecWebSocketAccept = "Sec-WebSocket-Accept"; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Utilities/IISCapability.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 7 | { 8 | [Flags] 9 | public enum IISCapability 10 | { 11 | None = 0, 12 | Websockets = 1, 13 | WindowsAuthentication = 2, 14 | PoolEnvironmentVariables = 4, 15 | ShutdownToken = 8, 16 | DynamicCompression = 16, 17 | ApplicationInitialization = 32, 18 | TracingModule = 64, 19 | FailedRequestTracingModule = 128, 20 | BasicAuthentication = 256 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/RequiresNewShim.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Microsoft.AspNetCore.Testing.xunit; 6 | 7 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 8 | { 9 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] 10 | public sealed class RequiresNewShimAttribute : Attribute, ITestCondition 11 | { 12 | public bool IsMet => !DeployerSelector.IsBackwardsCompatiblityTest; 13 | 14 | public string SkipReason => "Test verifies new behavior in the aspnetcorev2.dll that isn't supported in earlier versions."; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "requesthandler.h" 8 | 9 | class AppOfflineHandler: public REQUEST_HANDLER 10 | { 11 | public: 12 | AppOfflineHandler(IHttpContext& pContext, const std::string appOfflineContent) 13 | : REQUEST_HANDLER(pContext), 14 | m_pContext(pContext), 15 | m_strAppOfflineContent(appOfflineContent) 16 | { 17 | } 18 | 19 | REQUEST_NOTIFICATION_STATUS ExecuteRequestHandler() override; 20 | 21 | private: 22 | IHttpContext& m_pContext; 23 | std::string m_strAppOfflineContent; 24 | }; 25 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/RequiresNewHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Microsoft.AspNetCore.Testing.xunit; 6 | 7 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 8 | { 9 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] 10 | public sealed class RequiresNewHandlerAttribute : Attribute, ITestCondition 11 | { 12 | public bool IsMet => !DeployerSelector.IsForwardsCompatibilityTest; 13 | 14 | public string SkipReason => "Test verifies new behavior in the aspnetcorev2_inprocess.dll that isn't supported in earlier versions."; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/SkipVSTSAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Microsoft.AspNetCore.Server.IntegrationTesting; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | 8 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 9 | { 10 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] 11 | public sealed class SkipInVSTSAttribute : Attribute, ITestCondition 12 | { 13 | public bool IsMet => string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SYSTEM_TASKDEFINITIONSURI")); 14 | 15 | public string SkipReason => "Running in VSTS"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/StdWrapper.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | // Wraps stdout/stderr stream, modifying them to redirect to the given handle 9 | class StdWrapper 10 | { 11 | public: 12 | StdWrapper(FILE* stdStream, DWORD stdHandleNumber, HANDLE handleToRedirectTo, BOOL fEnableNativeRedirection); 13 | ~StdWrapper(); 14 | HRESULT StartRedirection(); 15 | HRESULT StopRedirection() const; 16 | 17 | private: 18 | int m_previousFileDescriptor; 19 | FILE* m_stdStream; 20 | DWORD m_stdHandleNumber; 21 | BOOL m_enableNativeRedirection; 22 | HANDLE m_handleToRedirectTo; 23 | FILE* m_redirectedFile; 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/Core/IISConfigurationData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace Microsoft.AspNetCore.Server.IIS.Core 8 | { 9 | [StructLayout(LayoutKind.Sequential)] 10 | internal struct IISConfigurationData 11 | { 12 | public IntPtr pNativeApplication; 13 | [MarshalAs(UnmanagedType.BStr)] 14 | public string pwzFullApplicationPath; 15 | [MarshalAs(UnmanagedType.BStr)] 16 | public string pwzVirtualApplicationPath; 17 | public bool fWindowsAuthEnabled; 18 | public bool fBasicAuthEnabled; 19 | public bool fAnonymousAuthEnable; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/WebSites/StressTestWebSite/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.Extensions.Logging; 6 | 7 | namespace ANCMStressTestApp 8 | { 9 | public class Program 10 | { 11 | public static void Main(string[] args) 12 | { 13 | var host = new WebHostBuilder() 14 | .ConfigureLogging((_, factory) => 15 | { 16 | factory.AddConsole(); 17 | }) 18 | .UseKestrel() 19 | .UseIISIntegration() 20 | .UseStartup() 21 | .Build(); 22 | 23 | host.Run(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/Common.Tests/Utilities/DisposableList.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace Microsoft.AspNetCore.Server.IntegrationTesting 8 | { 9 | public class DisposableList : List, IDisposable where T : IDisposable 10 | { 11 | public DisposableList() : base() { } 12 | 13 | public DisposableList(IEnumerable collection) : base(collection) { } 14 | 15 | public DisposableList(int capacity) : base(capacity) { } 16 | 17 | public void Dispose() 18 | { 19 | foreach (var item in this) 20 | { 21 | item?.Dispose(); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /samples/IISSample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:25334/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development", 16 | "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Server.IISIntegration" 17 | } 18 | }, 19 | "IISSample": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/InProcessRequestHandler/InProcessApplicationBase.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "AppOfflineTrackingApplication.h" 7 | 8 | typedef INT(*hostfxr_main_fn) (CONST DWORD argc, CONST PCWSTR argv[]); // TODO these may need to be BSTRs 9 | 10 | class InProcessApplicationBase : public AppOfflineTrackingApplication 11 | { 12 | public: 13 | 14 | InProcessApplicationBase( 15 | IHttpServer& pHttpServer, 16 | IHttpApplication& pHttpApplication); 17 | 18 | ~InProcessApplicationBase() = default; 19 | 20 | VOID StopInternal(bool fServerInitiated) override; 21 | 22 | protected: 23 | BOOL m_fRecycleCalled; 24 | IHttpServer& m_pHttpServer; 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /test/IIS.Tests/Utilities/SkipIfHostableWebCoreNotAvailibleAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | 8 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 9 | { 10 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] 11 | public sealed class SkipIfHostableWebCoreNotAvailableAttribute : Attribute, ITestCondition 12 | { 13 | public bool IsMet { get; } = File.Exists(TestServer.HostableWebCoreLocation); 14 | 15 | public string SkipReason { get; } = $"Hostable Web Core not available, {TestServer.HostableWebCoreLocation} not found."; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Utilities/SkipIfDebugAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Microsoft.AspNetCore.Server.IntegrationTesting; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | 8 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 9 | { 10 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] 11 | public sealed class SkipIfDebugAttribute : Attribute, ITestCondition 12 | { 13 | public bool IsMet => 14 | #if DEBUG 15 | false; 16 | #else 17 | true; 18 | #endif 19 | 20 | public string SkipReason => "Test cannot be run in Debug mode."; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/WebConfigConfigurationSource.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | #include 6 | #include "ConfigurationSection.h" 7 | #include "ConfigurationSource.h" 8 | 9 | class WebConfigConfigurationSource: public ConfigurationSource 10 | { 11 | public: 12 | WebConfigConfigurationSource(IAppHostAdminManager *pAdminManager, const IHttpApplication &pHttpApplication) noexcept 13 | : m_manager(pAdminManager), 14 | m_application(pHttpApplication) 15 | { 16 | } 17 | 18 | std::shared_ptr GetSection(const std::wstring& name) const override; 19 | 20 | private: 21 | CComPtr m_manager; 22 | const IHttpApplication &m_application; 23 | }; 24 | -------------------------------------------------------------------------------- /tools/UpdateIISExpressCertificate.ps1: -------------------------------------------------------------------------------- 1 | $cert = New-SelfSignedCertificate -DnsName "localhost", "localhost" -CertStoreLocation "cert:\LocalMachine\My" -NotAfter (Get-Date).AddYears(5) 2 | $thumb = $cert.GetCertHashString() 3 | 4 | $Store = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList 'root', 'LocalMachine' 5 | $Store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite) 6 | $Store.Add($cert) 7 | $Store.Close() 8 | 9 | $tempFile = [System.IO.Path]::GetTempFileName(); 10 | $content = ""; 11 | 12 | for ($i=44300; $i -le 44399; $i++) { 13 | $content += "http delete sslcert ipport=0.0.0.0:$i`n"; 14 | $content += "http add sslcert ipport=0.0.0.0:$i certhash=$thumb appid=`{214124cd-d05b-4309-9af9-9caa44b2b74a`}`n"; 15 | } 16 | 17 | [IO.File]::WriteAllLines($tempFile, $content) 18 | 19 | netsh -f $tempFile 20 | Remove-Item $tempFile; -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/WebConfigConfigurationSource.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include "WebConfigConfigurationSource.h" 5 | 6 | #include "exceptions.h" 7 | #include "WebConfigConfigurationSection.h" 8 | 9 | std::shared_ptr WebConfigConfigurationSource::GetSection(const std::wstring& name) const 10 | { 11 | const CComBSTR bstrAspNetCoreSection = name.c_str(); 12 | const CComBSTR applicationConfigPath = m_application.GetAppConfigPath(); 13 | 14 | IAppHostElement* sectionElement; 15 | if (LOG_IF_FAILED(m_manager->GetAdminSection(bstrAspNetCoreSection, applicationConfigPath, §ionElement))) 16 | { 17 | return nullptr; 18 | } 19 | return std::make_unique(sectionElement); 20 | } 21 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Server.IISIntegration.Tests/Microsoft.AspNetCore.Server.IISIntegration.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(StandardTestTfms) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.appveyor.yml: -------------------------------------------------------------------------------- 1 | init: 2 | # Reset dynamic port range from AppVeyor setting (1025-65535) to Windows default (49152-65535), 3 | # to prevent conflicts with ANCM random ports (1025-48000). 4 | - netsh int ipv4 show dynamicport tcp 5 | - netsh int ipv4 set dynamic tcp start=49152 num=16384 6 | - netsh int ipv4 show dynamicport tcp 7 | 8 | - git config --global core.autocrlf true 9 | branches: 10 | only: 11 | - master 12 | - /^release\/.*$/ 13 | - /^(.*\/)?ci-.*$/ 14 | install: 15 | - ps: .\tools\update_schema.ps1 16 | - git submodule update --init --recursive 17 | - net start w3svc 18 | build_script: 19 | - ps: .\run.ps1 default-build /p:SkipIISBackwardsCompatibilityTests=true /p:SkipIISForwardsCompatibilityTests=true 20 | clone_depth: 1 21 | environment: 22 | global: 23 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true 24 | DOTNET_CLI_TELEMETRY_OPTOUT: 1 25 | test: 'off' 26 | deploy: 'off' 27 | os: Visual Studio 2017 28 | -------------------------------------------------------------------------------- /test/IIS.Tests/StrictTestServerTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.Logging; 6 | using Microsoft.Extensions.Logging.Testing; 7 | using Xunit; 8 | 9 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 10 | { 11 | public class StrictTestServerTests: LoggedTest 12 | { 13 | public override void Dispose() 14 | { 15 | base.Dispose(); 16 | Assert.DoesNotContain(TestSink.Writes, w => w.LogLevel > LogLevel.Information); 17 | } 18 | 19 | protected static TaskCompletionSource CreateTaskCompletionSource() 20 | { 21 | return new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/file_utility.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "stdafx.h" 7 | 8 | #include 9 | #include "stringu.h" 10 | 11 | class FILE_UTILITY 12 | { 13 | public: 14 | 15 | static 16 | HRESULT 17 | ConvertPathToFullPath( 18 | _In_ LPCWSTR pszPath, 19 | _In_ LPCWSTR pszRootPath, 20 | _Out_ STRU* pStrFullPath 21 | ); 22 | 23 | static 24 | HRESULT 25 | EnsureDirectoryPathExist( 26 | _In_ LPCWSTR pszPath 27 | ); 28 | 29 | static 30 | std::string 31 | GetHtml(HMODULE module, int page); 32 | 33 | private: 34 | static 35 | HRESULT 36 | IsPathUnc( 37 | __in LPCWSTR pszPath, 38 | __out BOOL * pfIsUnc 39 | ); 40 | 41 | }; 42 | 43 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/GlobalVersionUtility.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #pragma once 5 | 6 | #include "fx_ver.h" 7 | 8 | class GlobalVersionUtility 9 | { 10 | public: 11 | 12 | static 13 | std::wstring 14 | GetGlobalRequestHandlerPath(PCWSTR pwzAspNetCoreFolderPath, PCWSTR pwzHandlerVersion, PCWSTR pwzHandlerName); 15 | 16 | static 17 | std::wstring 18 | FindHighestGlobalVersion(PCWSTR pwzAspNetCoreFolderPath); 19 | 20 | static 21 | std::wstring 22 | RemoveFileNameFromFolderPath(std::wstring fileName); 23 | 24 | static 25 | std::vector 26 | GetRequestHandlerVersions(PCWSTR pwzAspNetCoreFolderPath); 27 | 28 | static 29 | std::wstring 30 | GetModuleName(HMODULE hModuleName); 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /test/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | netcoreapp2.2 8 | $(DeveloperBuildTestTfms) 9 | $(StandardTestTfms) 10 | $(StandardTestTfms);net461 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/EventTracing.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #pragma warning( push ) 9 | #pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS ) 10 | 11 | #include "aspnetcore_event.h" 12 | 13 | #pragma warning( pop ) 14 | 15 | template< class EVENT, typename ...Params > 16 | void RaiseEvent(IHttpTraceContext * pTraceContext,Params&&... params) 17 | { 18 | if (pTraceContext != nullptr && EVENT::IsEnabled(pTraceContext)) 19 | { 20 | EVENT::RaiseEvent(pTraceContext, std::forward(params)...); 21 | } 22 | } 23 | 24 | template< class EVENT, typename ...Params > 25 | void RaiseEvent(IHttpContext * pHttpContext,Params&&... params) 26 | { 27 | ::RaiseEvent(pHttpContext->GetTraceContext(), std::forward(params)...); 28 | } 29 | -------------------------------------------------------------------------------- /test/WebSites/InProcessWebSite/DummyServer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Hosting.Server; 8 | using Microsoft.AspNetCore.Http.Features; 9 | 10 | namespace TestSite 11 | { 12 | public class DummyServer : IServer 13 | { 14 | public void Dispose() 15 | { 16 | } 17 | 18 | public Task StartAsync(IHttpApplication application, CancellationToken cancellationToken) 19 | { 20 | return Task.Delay(TimeSpan.MaxValue); 21 | } 22 | 23 | public Task StopAsync(CancellationToken cancellationToken) 24 | { 25 | return Task.Delay(TimeSpan.MaxValue); 26 | } 27 | 28 | public IFeatureCollection Features { get; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/AppOfflineApplication.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "application.h" 7 | #include "requesthandler.h" 8 | #include "PollingAppOfflineApplication.h" 9 | 10 | class AppOfflineApplication: public PollingAppOfflineApplication 11 | { 12 | public: 13 | AppOfflineApplication(const IHttpApplication& pApplication) 14 | : PollingAppOfflineApplication(pApplication, PollingAppOfflineApplicationMode::StopWhenRemoved) 15 | { 16 | CheckAppOffline(); 17 | } 18 | 19 | HRESULT CreateHandler(IHttpContext* pHttpContext, IREQUEST_HANDLER** pRequestHandler) override; 20 | 21 | HRESULT OnAppOfflineFound() override; 22 | 23 | static bool ShouldBeStarted(const IHttpApplication& pApplication); 24 | 25 | private: 26 | std::string m_strAppOfflineContent; 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /test/IISExpress.FunctionalTests/RequiresIISAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Microsoft.AspNetCore.Server.IntegrationTesting; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | 8 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 9 | { 10 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] 11 | public sealed class RequiresIISAttribute : Attribute, ITestCondition 12 | { 13 | public bool IsMet => IISExpressAncmSchema.SupportsInProcessHosting; 14 | 15 | public string SkipReason => IISExpressAncmSchema.SkipReason; 16 | 17 | public RequiresIISAttribute() { } 18 | 19 | public RequiresIISAttribute(IISCapability capabilities) 20 | { 21 | // IISCapabilities aren't pertinent to IISExpress 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/SkipIfNotAdminAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Security.Principal; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | 8 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 9 | { 10 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] 11 | public sealed class SkipIfNotAdminAttribute : Attribute, ITestCondition 12 | { 13 | public bool IsMet 14 | { 15 | get 16 | { 17 | var identity = WindowsIdentity.GetCurrent(); 18 | var principal = new WindowsPrincipal(identity); 19 | return principal.IsInRole(WindowsBuiltInRole.Administrator); 20 | } 21 | } 22 | 23 | public string SkipReason => "The current process is not running as admin."; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/WebConfigConfigurationSection.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include "ConfigurationSection.h" 9 | 10 | class WebConfigConfigurationSection: public ConfigurationSection 11 | { 12 | public: 13 | WebConfigConfigurationSection(IAppHostElement* pElement) 14 | : m_element(pElement) 15 | { 16 | } 17 | 18 | std::optional GetString(const std::wstring& name) const override; 19 | std::optional GetBool(const std::wstring& name) const override; 20 | std::optional GetLong(const std::wstring& name) const override; 21 | std::optional GetTimespan(const std::wstring& name) const override; 22 | std::vector> GetKeyValuePairs(const std::wstring& name) const override; 23 | 24 | private: 25 | CComPtr m_element; 26 | }; 27 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Utilities/RequiresEnvironmentVariableAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Microsoft.AspNetCore.Server.IntegrationTesting; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | 8 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 9 | { 10 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] 11 | public sealed class RequiresEnvironmentVariableAttribute : Attribute, ITestCondition 12 | { 13 | private readonly string _name; 14 | 15 | public RequiresEnvironmentVariableAttribute(string name) 16 | { 17 | _name = name; 18 | } 19 | 20 | public bool IsMet => !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(_name)); 21 | 22 | public string SkipReason => $"Environment variable {_name} is required to run this test."; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/IIS.Shared.FunctionalTests/MofFileTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Diagnostics; 5 | using System.IO; 6 | using Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests; 7 | using Microsoft.AspNetCore.Testing; 8 | using Microsoft.AspNetCore.Testing.xunit; 9 | using Xunit; 10 | 11 | namespace IIS.FunctionalTests 12 | { 13 | public class MofFileTests 14 | { 15 | [ConditionalFact] 16 | [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] 17 | [RequiresIIS(IISCapability.TracingModule)] 18 | public void CheckMofFile() 19 | { 20 | var path = Path.Combine(TestPathUtilities.GetSolutionRootDirectory("IISIntegration"), "src", "aspnetcoremodulev2", "aspnetcore", "ancm.mof"); 21 | var process = Process.Start("mofcomp.exe", path); 22 | process.WaitForExit(); 23 | Assert.Equal(0, process.ExitCode); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/FileOutputManager.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "sttimer.h" 7 | #include "HandleWrapper.h" 8 | #include "StdWrapper.h" 9 | #include "stringa.h" 10 | #include "stringu.h" 11 | #include "BaseOutputManager.h" 12 | 13 | class FileOutputManager : public BaseOutputManager 14 | { 15 | #define MAX_FILE_READ_SIZE 30000 16 | public: 17 | FileOutputManager(std::wstring pwzApplicationPath, std::wstring pwzStdOutLogFileName); 18 | FileOutputManager(std::wstring pwzApplicationPath, std::wstring pwzStdOutLogFileName, bool fEnableNativeLogging); 19 | ~FileOutputManager(); 20 | 21 | virtual std::wstring GetStdOutContent() override; 22 | void Start() override; 23 | void Stop() override; 24 | 25 | private: 26 | HandleWrapper m_hLogFileHandle; 27 | std::wstring m_stdOutLogFileName; 28 | std::filesystem::path m_applicationPath; 29 | std::filesystem::path m_logFilePath; 30 | }; 31 | -------------------------------------------------------------------------------- /test/Common.Tests/Utilities/TimeoutExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Runtime.CompilerServices; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Testing; 8 | 9 | namespace Microsoft.AspNetCore.Server.IntegrationTesting 10 | { 11 | 12 | public static class TimeoutExtensions 13 | { 14 | public static TimeSpan DefaultTimeoutValue = TimeSpan.FromSeconds(300); 15 | 16 | public static Task DefaultTimeout(this Task task, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = -1) 17 | { 18 | return task.TimeoutAfter(DefaultTimeoutValue, filePath, lineNumber); 19 | } 20 | 21 | public static Task DefaultTimeout(this Task task, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = -1) 22 | { 23 | return task.TimeoutAfter(DefaultTimeoutValue, filePath, lineNumber); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Inprocess/FixtureLoggedTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Reflection; 5 | using Microsoft.Extensions.Logging.Testing; 6 | using Xunit.Abstractions; 7 | 8 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 9 | { 10 | public class FixtureLoggedTest: LoggedTest 11 | { 12 | private readonly IISTestSiteFixture _fixture; 13 | 14 | public FixtureLoggedTest(IISTestSiteFixture fixture) 15 | { 16 | _fixture = fixture; 17 | } 18 | 19 | public override void Initialize(MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) 20 | { 21 | base.Initialize(methodInfo, testMethodArguments, testOutputHelper); 22 | _fixture.Attach(this); 23 | } 24 | 25 | public override void Dispose() 26 | { 27 | _fixture.Detach(this); 28 | base.Dispose(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/OutOfProcessRequestHandler/protocolconfig.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include "protocolconfig.h" 5 | #include "exceptions.h" 6 | 7 | HRESULT 8 | PROTOCOL_CONFIG::Initialize() 9 | { 10 | m_fKeepAlive = TRUE; 11 | m_msTimeout = 120000; 12 | m_fPreserveHostHeader = TRUE; 13 | m_fReverseRewriteHeaders = FALSE; 14 | 15 | RETURN_IF_FAILED(m_strXForwardedForName.CopyW(L"X-Forwarded-For")); 16 | RETURN_IF_FAILED(m_strSslHeaderName.CopyW(L"X-Forwarded-Proto")); 17 | RETURN_IF_FAILED(m_strClientCertName.CopyW(L"MS-ASPNETCORE-CLIENTCERT")); 18 | 19 | m_fIncludePortInXForwardedFor = TRUE; 20 | m_dwMinResponseBuffer = 0; // no response buffering 21 | m_dwResponseBufferLimit = 4096*1024; 22 | m_dwMaxResponseHeaderSize = 65536; 23 | return S_OK; 24 | } 25 | 26 | VOID 27 | PROTOCOL_CONFIG::OverrideConfig( 28 | REQUESTHANDLER_CONFIG *pAspNetCoreConfig 29 | ) 30 | { 31 | m_msTimeout = pAspNetCoreConfig->QueryRequestTimeoutInMS(); 32 | } 33 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.doc diff=astextplain 2 | *.DOC diff=astextplain 3 | *.docx diff=astextplain 4 | *.DOCX diff=astextplain 5 | *.dot diff=astextplain 6 | *.DOT diff=astextplain 7 | *.pdf diff=astextplain 8 | *.PDF diff=astextplain 9 | *.rtf diff=astextplain 10 | *.RTF diff=astextplain 11 | 12 | *.jpg binary 13 | *.png binary 14 | *.gif binary 15 | 16 | *.cs text=auto diff=csharp 17 | *.vb text=auto 18 | *.resx text=auto 19 | *.c text=auto 20 | *.cpp text=auto 21 | *.cxx text=auto 22 | *.h text=auto 23 | *.hxx text=auto 24 | *.py text=auto 25 | *.rb text=auto 26 | *.java text=auto 27 | *.html text=auto 28 | *.htm text=auto 29 | *.css text=auto 30 | *.scss text=auto 31 | *.sass text=auto 32 | *.less text=auto 33 | *.js text=auto 34 | *.lisp text=auto 35 | *.clj text=auto 36 | *.sql text=auto 37 | *.php text=auto 38 | *.lua text=auto 39 | *.m text=auto 40 | *.asm text=auto 41 | *.erl text=auto 42 | *.fs text=auto 43 | *.fsx text=auto 44 | *.hs text=auto 45 | *.rc text=auto 46 | 47 | *.vcxproj text=auto 48 | *.csproj text=auto 49 | *.vbproj text=auto 50 | *.fsproj text=auto 51 | *.dbproj text=auto 52 | *.sln text=auto eol=crlf 53 | *.sh eol=lf 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ASP.NET Core IISIntegration [Archived] 2 | ====================================== 3 | 4 | **This GitHub project has been archived.** Ongoing development on this project can be found in . 5 | 6 | This repo hosts the ASP.NET Core middleware for IIS integration and the ASP.NET Core Module. 7 | 8 | This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the [Home](https://github.com/aspnet/home) repo. 9 | 10 | ## Building from source 11 | 1. Install prerequisites 12 | 1. Visual Studio 2017 13 | 1. Workload: `Desktop development with C++` 14 | 1. Run `run.ps1 install vs` or install the following components 15 | 1. Additional Component: `Windows 8.1 SDK and UCRT SDK` 16 | 2. Additional Component: `Windows 10 SDK (10.0.15063.0) for Desktop C++ [x86 and x64]` 17 | 2. Workload: `ASP.NET and web development` 18 | 2. Clone with submodules 19 | 1. `git clone --recurse-submodules IISIntegration` 20 | 2. OR run `git submodule update --init --recursive` after initial clone 21 | 3. `build.cmd` 22 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/globalmodule.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "applicationmanager.h" 7 | 8 | class ASPNET_CORE_GLOBAL_MODULE : NonCopyable, public CGlobalModule 9 | { 10 | 11 | public: 12 | 13 | ASPNET_CORE_GLOBAL_MODULE( 14 | std::shared_ptr pApplicationManager 15 | ) noexcept; 16 | 17 | virtual ~ASPNET_CORE_GLOBAL_MODULE() = default; 18 | 19 | VOID Terminate() override 20 | { 21 | LOG_INFO(L"ASPNET_CORE_GLOBAL_MODULE::Terminate"); 22 | // Remove the class from memory. 23 | delete this; 24 | } 25 | 26 | GLOBAL_NOTIFICATION_STATUS 27 | OnGlobalStopListening( 28 | _In_ IGlobalStopListeningProvider * pProvider 29 | ) override; 30 | 31 | GLOBAL_NOTIFICATION_STATUS 32 | OnGlobalConfigurationChange( 33 | _In_ IGlobalConfigurationChangeProvider * pProvider 34 | ) override; 35 | 36 | private: 37 | std::shared_ptr m_pApplicationManager; 38 | }; 39 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/IServerVariableFeature.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.AspNetCore.Http.Features 5 | { 6 | /// 7 | /// This feature provides access to request server variables set. 8 | /// 9 | /// This feature is only available when hosting ASP.NET Core in-process with IIS or IIS Express. 10 | /// 11 | /// 12 | /// 13 | /// For a list of common server variables available in IIS, see http://go.microsoft.com/fwlink/?LinkId=52471. 14 | /// 15 | public interface IServerVariablesFeature 16 | { 17 | /// 18 | /// Gets or sets the value of a server variable for the current request. 19 | /// 20 | /// The variable name 21 | /// May return null or empty if the variable does not exist or is not set. 22 | string this[string variableName] { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Microsoft ASP.NET Core 12 | https://github.com/aspnet/IISIntegration 13 | git 14 | $(MSBuildThisFileDirectory) 15 | $(MSBuildThisFileDirectory)build\Key.snk 16 | true 17 | true 18 | 19 | false 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Utilities/IISTestSiteCollection.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Xunit; 5 | 6 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 7 | { 8 | /// 9 | /// This type just maps collection names to available fixtures 10 | /// 11 | [CollectionDefinition(Name)] 12 | public class IISTestSiteCollection : ICollectionFixture 13 | { 14 | public const string Name = nameof(IISTestSiteCollection); 15 | } 16 | 17 | [CollectionDefinition(Name)] 18 | public class OutOfProcessTestSiteCollection : ICollectionFixture 19 | { 20 | public const string Name = nameof(OutOfProcessTestSiteCollection); 21 | } 22 | 23 | [CollectionDefinition(Name)] 24 | public class OutOfProcessV1TestSiteCollection : ICollectionFixture 25 | { 26 | public const string Name = nameof(OutOfProcessV1TestSiteCollection); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /.vsts-pipelines/builds/ci-internal-21.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | - release/2.2 3 | 4 | resources: 5 | repositories: 6 | - repository: buildtools 7 | type: git 8 | name: aspnet-BuildTools 9 | ref: refs/heads/release/2.2 10 | 11 | phases: 12 | - template: .azure\templates\jobs\default-build.yml@buildtools 13 | parameters: 14 | agentOs: Windows 15 | codeSign: false 16 | buildArgs: /p:BuildServerIIS21=true /p:SkipIISExpressTests=true /p:SkipIISBackwardsCompatibilityTests=true /p:SkipIISForwardsCompatibilityTests=true 17 | beforeBuild: 18 | - powershell: "& ./tools/UpdateIISExpressCertificate.ps1; & ./tools/update_schema.ps1; & ./tools/SetupTestEnvironment.ps1 SetupDumps" 19 | displayName: Prepare repo 20 | afterBuild: 21 | - powershell: "& ./tools/SetupTestEnvironment.ps1 Shutdown" 22 | displayName: Stop AppVerifier 23 | condition: always() 24 | - task: PublishBuildArtifacts@1 25 | displayName: Upload logs 26 | condition: eq(variables['system.pullrequest.isfork'], false) 27 | inputs: 28 | artifactName: logs 29 | artifactType: Container 30 | pathtoPublish: artifacts/logs -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Inprocess/HelloWorldTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Testing.xunit; 6 | using Xunit; 7 | 8 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 9 | { 10 | [Collection(IISTestSiteCollection.Name)] 11 | public class HelloWorldInProcessTests 12 | { 13 | private readonly IISTestSiteFixture _fixture; 14 | 15 | public HelloWorldInProcessTests(IISTestSiteFixture fixture) 16 | { 17 | _fixture = fixture; 18 | } 19 | 20 | [ConditionalFact] 21 | public async Task HelloWorld_InProcess() 22 | { 23 | Assert.Equal("Hello World", await _fixture.Client.GetStringAsync("/HelloWorld")); 24 | 25 | Assert.Equal("/Path??", await _fixture.Client.GetStringAsync("/HelloWorld/Path%3F%3F?query")); 26 | 27 | Assert.Equal("?query", await _fixture.Client.GetStringAsync("/HelloWorld/Query%3F%3F?query")); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Inprocess/FeatureCollectionTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Testing.xunit; 6 | using Xunit; 7 | 8 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 9 | { 10 | [Collection(IISTestSiteCollection.Name)] 11 | public class FeatureCollectionTest 12 | { 13 | private readonly IISTestSiteFixture _fixture; 14 | 15 | public FeatureCollectionTest(IISTestSiteFixture fixture) 16 | { 17 | _fixture = fixture; 18 | } 19 | 20 | [ConditionalTheory] 21 | [InlineData("FeatureCollectionSetRequestFeatures")] 22 | [InlineData("FeatureCollectionSetResponseFeatures")] 23 | [InlineData("FeatureCollectionSetConnectionFeatures")] 24 | public async Task FeatureCollectionTest_SetHttpContextFeatures(string path) 25 | { 26 | Assert.Equal("Success", await _fixture.Client.GetStringAsync(path + "/path" + "?query")); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /samples/NativeIISSample/NativeIISSample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | netcoreapp2.2 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | inprocess 23 | 24 | 25 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Inprocess/ResponseInvalidOrderingTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Server.IntegrationTesting; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | using Xunit; 8 | 9 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 10 | { 11 | [Collection(IISTestSiteCollection.Name)] 12 | public class ResponseInvalidOrderingTest 13 | { 14 | private readonly IISTestSiteFixture _fixture; 15 | 16 | public ResponseInvalidOrderingTest(IISTestSiteFixture fixture) 17 | { 18 | _fixture = fixture; 19 | } 20 | 21 | [ConditionalTheory] 22 | [InlineData("SetStatusCodeAfterWrite")] 23 | [InlineData("SetHeaderAfterWrite")] 24 | public async Task ResponseInvalidOrderingTests_ExpectFailure(string path) 25 | { 26 | Assert.Equal($"Started_{path}Threw_Finished", await _fixture.Client.GetStringAsync("/ResponseInvalidOrdering/" + path)); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/ConfigurationSource.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include "NonCopyable.h" 10 | #include "ConfigurationSection.h" 11 | 12 | #define CS_ASPNETCORE_SECTION L"system.webServer/aspNetCore" 13 | #define CS_WINDOWS_AUTHENTICATION_SECTION L"system.webServer/security/authentication/windowsAuthentication" 14 | #define CS_BASIC_AUTHENTICATION_SECTION L"system.webServer/security/authentication/basicAuthentication" 15 | #define CS_ANONYMOUS_AUTHENTICATION_SECTION L"system.webServer/security/authentication/anonymousAuthentication" 16 | 17 | class ConfigurationSource: NonCopyable 18 | { 19 | public: 20 | ConfigurationSource() = default; 21 | virtual ~ConfigurationSource() = default; 22 | virtual std::shared_ptr GetSection(const std::wstring& name) const = 0; 23 | std::shared_ptr GetRequiredSection(const std::wstring& name) const; 24 | }; 25 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/InProcessRequestHandler/StartupExceptionHandler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "requesthandler.h" 7 | #include "resource.h" 8 | #include "file_utility.h" 9 | 10 | 11 | class StartupExceptionHandler : public REQUEST_HANDLER 12 | { 13 | public: 14 | 15 | StartupExceptionHandler(IHttpContext& pContext, BOOL disableLogs, HRESULT hr) 16 | : m_pContext(pContext), 17 | m_disableLogs(disableLogs), 18 | m_HR(hr) 19 | { 20 | } 21 | 22 | ~StartupExceptionHandler() 23 | { 24 | } 25 | 26 | REQUEST_NOTIFICATION_STATUS OnExecuteRequestHandler() 27 | { 28 | static std::string s_html500Page = FILE_UTILITY::GetHtml(g_hModule, IN_PROCESS_SHIM_STATIC_HTML); 29 | 30 | WriteStaticResponse(m_pContext, s_html500Page, m_HR, m_disableLogs); 31 | 32 | return REQUEST_NOTIFICATION_STATUS::RQ_NOTIFICATION_FINISH_REQUEST; 33 | } 34 | 35 | private: 36 | IHttpContext& m_pContext; 37 | BOOL m_disableLogs; 38 | HRESULT m_HR; 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /test/WebSites/StressTestWebSite/StressTestWebSite.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $(StandardTestTfms) 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Oo]bj/ 2 | [Bb]in/ 3 | TestResults/ 4 | .nuget/ 5 | *.sln.ide/ 6 | _ReSharper.*/ 7 | packages/ 8 | artifacts/ 9 | PublishProfiles/ 10 | BenchmarkDotNet.Artifacts/ 11 | *.user 12 | *.suo 13 | *.cache 14 | *.docstates 15 | _ReSharper.* 16 | nuget.exe 17 | project.lock.json 18 | *net45.csproj 19 | *net451.csproj 20 | *k10.csproj 21 | *.psess 22 | *.vsp 23 | *.pidb 24 | *.userprefs 25 | *DS_Store 26 | *.ncrunchsolution 27 | *.*sdf 28 | *.ipch 29 | .vscode/ 30 | *.nuget.props 31 | *.nuget.targets 32 | *.bin 33 | *.vs/ 34 | .testPublish/ 35 | 36 | *.obj 37 | *.tlog 38 | *.CppClean.log 39 | *msbuild.log 40 | gtest.log 41 | 42 | src/*/*/Debug/ 43 | src/*/*/x64/Debug/ 44 | src/*/*/Release/ 45 | src/*/*/x64/Release/ 46 | x64/ 47 | 48 | *vcxproj.filters 49 | *.aps 50 | *.pdb 51 | *.lib 52 | *.idb 53 | *.TMP 54 | 55 | src/*/AspNetCore/aspnetcoremodule.h 56 | src/*/AspNetCore/aspnetcore_msg.h 57 | src/*/AspNetCore/aspnetcore_msg.rc 58 | src/*/*/version.h 59 | src/*/InProcessRequestHandler/version.h 60 | src/*/OutOfProcessRequestHandler/version.h 61 | src/*/CommonLib/aspnetcore_msg.h 62 | src/*/CommonLib/aspnetcore_msg.rc 63 | test/*/Debug 64 | test/*/Release 65 | .build 66 | 67 | *.VC.*db 68 | global.json 69 | msbuild.binlog 70 | -------------------------------------------------------------------------------- /test/CommonLibTests/exception_handler_tests.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #include "stdafx.h" 5 | 6 | TEST(CaughtExceptionHResult, ReturnsOutOfMemoryForBadAlloc) 7 | { 8 | HRESULT hr; 9 | try 10 | { 11 | throw std::bad_alloc(); 12 | } 13 | catch(...) 14 | { 15 | hr = CaughtExceptionHResult(); 16 | } 17 | 18 | EXPECT_EQ(E_OUTOFMEMORY, hr); 19 | } 20 | 21 | TEST(CaughtExceptionHResult, ReturnsValueForSystemError) 22 | { 23 | HRESULT hr; 24 | try 25 | { 26 | throw std::system_error(E_INVALIDARG, std::system_category()); 27 | } 28 | catch(...) 29 | { 30 | hr = CaughtExceptionHResult(); 31 | } 32 | 33 | EXPECT_EQ(E_INVALIDARG, hr); 34 | } 35 | 36 | TEST(CaughtExceptionHResult, ReturnsUhandledExceptionForOtherExceptions) 37 | { 38 | HRESULT hr; 39 | try 40 | { 41 | throw E_INVALIDARG; 42 | } 43 | catch(...) 44 | { 45 | hr = CaughtExceptionHResult(); 46 | } 47 | 48 | EXPECT_EQ(HRESULT_FROM_WIN32(ERROR_UNHANDLED_EXCEPTION), hr); 49 | } 50 | -------------------------------------------------------------------------------- /test/CommonLibTests/Helpers.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include "stdafx.h" 5 | 6 | std::wstring 7 | Helpers::ReadFileContent(std::wstring file) 8 | { 9 | std::wcout << file << std::endl; 10 | 11 | std::fstream t(file); 12 | std::stringstream buffer; 13 | buffer << t.rdbuf(); 14 | 15 | int nChars = MultiByteToWideChar(CP_ACP, 0, buffer.str().c_str(), -1, NULL, 0); 16 | 17 | std::wstring retVal(nChars, '\0'); 18 | 19 | MultiByteToWideChar(CP_UTF8, 0, buffer.str().c_str(), -1, retVal.data(), nChars); 20 | 21 | return retVal; 22 | } 23 | 24 | TempDirectory::TempDirectory() 25 | { 26 | UUID uuid; 27 | UuidCreate(&uuid); 28 | RPC_CSTR szUuid = NULL; 29 | if (UuidToStringA(&uuid, &szUuid) == RPC_S_OK) 30 | { 31 | m_path = std::filesystem::temp_directory_path() / reinterpret_cast(szUuid); 32 | RpcStringFreeA(&szUuid); 33 | return; 34 | } 35 | throw std::exception("Cannot create temp directory"); 36 | } 37 | 38 | TempDirectory::~TempDirectory() 39 | { 40 | std::filesystem::remove_all(m_path); 41 | } 42 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Server.IISIntegration.Tests/IISExtensionTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Linq; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.AspNetCore.TestHost; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using Xunit; 9 | 10 | namespace Microsoft.AspNetCore.Server.IISIntegration 11 | { 12 | public class IISExtensionTests 13 | { 14 | [Fact] 15 | public void CallingUseIISIntegrationMultipleTimesWorks() 16 | { 17 | 18 | var builder = new WebHostBuilder() 19 | .UseSetting("TOKEN", "TestToken") 20 | .UseSetting("PORT", "12345") 21 | .UseSetting("APPL_PATH", "/") 22 | .UseIISIntegration() 23 | .UseIISIntegration() 24 | .Configure(app => { }); 25 | var server = new TestServer(builder); 26 | 27 | var filters = server.Host.Services.GetServices() 28 | .OfType(); 29 | 30 | Assert.Single(filters); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /nuget/Microsoft.AspNetCore.AspNetCoreModuleV2.props.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ${AspNetCoreModuleOutOfProcessVersion} 5 | $(MSBuildThisFileDirectory)..\contentFiles\any\any\x64\aspnetcorev2.dll 6 | $(MSBuildThisFileDirectory)..\contentFiles\any\any\x86\aspnetcorev2.dll 7 | $(MSBuildThisFileDirectory)..\contentFiles\any\any\x64\aspnetcorev2_inprocess.dll 8 | $(MSBuildThisFileDirectory)..\contentFiles\any\any\x86\aspnetcorev2_inprocess.dll 9 | $(MSBuildThisFileDirectory)..\contentFiles\any\any\x64\$(AspNetCoreModuleOutOfProcessVersion)\aspnetcorev2_outofprocess.dll 10 | $(MSBuildThisFileDirectory)..\contentFiles\any\any\x86\$(AspNetCoreModuleOutOfProcessVersion)\aspnetcorev2_outofprocess.dll 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #include "AppOfflineHandler.h" 5 | 6 | #include "HandleWrapper.h" 7 | 8 | REQUEST_NOTIFICATION_STATUS AppOfflineHandler::ExecuteRequestHandler() 9 | { 10 | HTTP_DATA_CHUNK DataChunk {}; 11 | auto pResponse = m_pContext.GetResponse(); 12 | 13 | DBG_ASSERT(pResponse); 14 | 15 | // Ignore failure hresults as nothing we can do 16 | // Set fTrySkipCustomErrors to true as we want client see the offline content 17 | pResponse->SetStatus(503, "Service Unavailable", 0, S_OK, nullptr, TRUE); 18 | pResponse->SetHeader("Content-Type", 19 | "text/html", 20 | static_cast(strlen("text/html")), 21 | FALSE 22 | ); 23 | 24 | DataChunk.DataChunkType = HttpDataChunkFromMemory; 25 | DataChunk.FromMemory.pBuffer = m_strAppOfflineContent.data(); 26 | DataChunk.FromMemory.BufferLength = static_cast(m_strAppOfflineContent.size()); 27 | pResponse->WriteEntityChunkByReference(&DataChunk); 28 | 29 | return REQUEST_NOTIFICATION_STATUS::RQ_NOTIFICATION_FINISH_REQUEST; 30 | } 31 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/DisconnectHandler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "irequesthandler.h" 8 | 9 | class ASPNET_CORE_PROXY_MODULE; 10 | 11 | class DisconnectHandler final: public IHttpConnectionStoredContext 12 | { 13 | public: 14 | DisconnectHandler(IHttpConnection* pHttpConnection) 15 | : m_pHandler(nullptr), m_pHttpConnection(pHttpConnection), m_disconnectFired(false) 16 | { 17 | InitializeSRWLock(&m_handlerLock); 18 | } 19 | 20 | virtual 21 | ~DisconnectHandler() 22 | { 23 | RemoveHandler(); 24 | } 25 | 26 | void 27 | NotifyDisconnect() override; 28 | 29 | void 30 | CleanupStoredContext() noexcept override; 31 | 32 | void 33 | SetHandler(std::unique_ptr handler); 34 | 35 | void RemoveHandler() noexcept; 36 | 37 | private: 38 | SRWLOCK m_handlerLock {}; 39 | std::unique_ptr m_pHandler; 40 | IHttpConnection* m_pHttpConnection; 41 | bool m_disconnectFired; 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/Core/ThrowingWasUpgradedWriteOnlyStream.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace Microsoft.AspNetCore.Server.IIS.Core 10 | { 11 | public class ThrowingWasUpgradedWriteOnlyStream : WriteOnlyStream 12 | { 13 | public override void Write(byte[] buffer, int offset, int count) 14 | => throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded); 15 | 16 | public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) 17 | => throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded); 18 | 19 | public override void Flush() 20 | => throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded); 21 | 22 | public override long Seek(long offset, SeekOrigin origin) 23 | => throw new NotSupportedException(); 24 | 25 | public override void SetLength(long value) 26 | => throw new NotSupportedException(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/ModuleHelpers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | #include "HandleWrapper.h" 6 | #include "exceptions.h" 7 | 8 | extern HMODULE g_hModule; 9 | 10 | class ModuleHelpers 11 | { 12 | public: 13 | static 14 | void IncrementCurrentModuleRefCount(HandleWrapper &handle) 15 | { 16 | WCHAR path[MAX_PATH]; 17 | 18 | #pragma warning( push ) 19 | #pragma warning ( disable : 26485 ) // Calling WinAPI causes expected array to pointer decay 20 | 21 | THROW_LAST_ERROR_IF(!GetModuleFileName(g_hModule, path, MAX_PATH)); 22 | THROW_LAST_ERROR_IF(!GetModuleHandleEx(0, path, &handle)); 23 | 24 | #pragma warning( pop ) 25 | } 26 | 27 | template 28 | static 29 | Func GetKnownProcAddress(HMODULE hModule, LPCSTR lpProcName) { 30 | 31 | #pragma warning( push ) 32 | #pragma warning ( disable : 26490 ) // Disable Don't use reinterpret_cast 33 | auto proc = reinterpret_cast(GetProcAddress(hModule, lpProcName)); 34 | #pragma warning( pop ) 35 | 36 | THROW_LAST_ERROR_IF (!proc); 37 | return proc; 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/Core/IO/AsyncIOEngine.Write.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Microsoft.AspNetCore.HttpSys.Internal; 6 | 7 | namespace Microsoft.AspNetCore.Server.IIS.Core.IO 8 | { 9 | internal partial class AsyncIOEngine 10 | { 11 | private class AsyncWriteOperation : AsyncWriteOperationBase 12 | { 13 | private readonly AsyncIOEngine _engine; 14 | 15 | public AsyncWriteOperation(AsyncIOEngine engine) 16 | { 17 | _engine = engine; 18 | } 19 | 20 | protected override unsafe int WriteChunks(IntPtr requestHandler, int chunkCount, HttpApiTypes.HTTP_DATA_CHUNK* dataChunks, 21 | out bool completionExpected) 22 | { 23 | return NativeMethods.HttpWriteResponseBytes(requestHandler, dataChunks, chunkCount, out completionExpected); 24 | } 25 | 26 | protected override void ResetOperation() 27 | { 28 | base.ResetOperation(); 29 | 30 | _engine.ReturnOperation(this); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /samples/IISSample/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/AspNetCore/src/protocolconfig.cxx: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include "precomp.hxx" 5 | 6 | HRESULT 7 | PROTOCOL_CONFIG::Initialize() 8 | { 9 | HRESULT hr; 10 | STRU strTemp; 11 | 12 | m_fKeepAlive = TRUE; 13 | m_msTimeout = 120000; 14 | m_fPreserveHostHeader = TRUE; 15 | m_fReverseRewriteHeaders = FALSE; 16 | 17 | if (FAILED(hr = m_strXForwardedForName.CopyW(L"X-Forwarded-For"))) 18 | { 19 | goto Finished; 20 | } 21 | 22 | if (FAILED(hr = m_strSslHeaderName.CopyW(L"X-Forwarded-Proto"))) 23 | { 24 | goto Finished; 25 | } 26 | 27 | if (FAILED(hr = m_strClientCertName.CopyW(L"MS-ASPNETCORE-CLIENTCERT"))) 28 | { 29 | goto Finished; 30 | } 31 | 32 | m_fIncludePortInXForwardedFor = TRUE; 33 | m_dwMinResponseBuffer = 0; // no response buffering 34 | m_dwResponseBufferLimit = 4096*1024; 35 | m_dwMaxResponseHeaderSize = 65536; 36 | 37 | Finished: 38 | 39 | return hr; 40 | } 41 | 42 | VOID 43 | PROTOCOL_CONFIG::OverrideConfig( 44 | ASPNETCORE_CONFIG *pAspNetCoreConfig 45 | ) 46 | { 47 | m_msTimeout = pAspNetCoreConfig->QueryRequestTimeoutInMS(); 48 | } -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/PipeOutputManager.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "StdWrapper.h" 7 | #include "stringu.h" 8 | #include "BaseOutputManager.h" 9 | 10 | class PipeOutputManager : public BaseOutputManager 11 | { 12 | // Timeout to be used if a thread never exits 13 | #define PIPE_OUTPUT_THREAD_TIMEOUT 2000 14 | 15 | // Max event log message is ~32KB, limit pipe size just below that. 16 | #define MAX_PIPE_READ_SIZE 30000 17 | public: 18 | PipeOutputManager(); 19 | PipeOutputManager(bool fEnableNativeLogging); 20 | ~PipeOutputManager(); 21 | 22 | void Start() override; 23 | void Stop() override; 24 | std::wstring GetStdOutContent() override; 25 | 26 | // Thread functions 27 | void ReadStdErrHandleInternal(); 28 | 29 | static void ReadStdErrHandle(LPVOID pContext); 30 | 31 | private: 32 | 33 | HANDLE m_hErrReadPipe; 34 | HANDLE m_hErrWritePipe; 35 | HANDLE m_hErrThread; 36 | CHAR m_pipeContents[MAX_PIPE_READ_SIZE] = { 0 }; 37 | DWORD m_numBytesReadTotal; 38 | }; 39 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/IISServerOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.AspNetCore.Builder 5 | { 6 | public class IISServerOptions 7 | { 8 | /// 9 | /// If true the server should set HttpContext.User. If false the server will only provide an 10 | /// identity when explicitly requested by the AuthenticationScheme. 11 | /// Note Windows Authentication must also be enabled in IIS for this to work. 12 | /// 13 | public bool AutomaticAuthentication { get; set; } = true; 14 | 15 | /// 16 | /// Sets the display name shown to users on login pages. The default is null. 17 | /// 18 | public string AuthenticationDisplayName { get; set; } 19 | 20 | /// 21 | /// Used to indicate if the authentication handler should be registered. This is only done if ANCM indicates 22 | /// IIS has a non-anonymous authentication enabled, or for back compat with ANCMs that did not provide this information. 23 | /// 24 | internal bool ForwardWindowsAuthentication { get; set; } = true; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/WebSites/InProcessWebSite/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Utilities/LogFileTestBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests; 7 | using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; 8 | using Xunit.Abstractions; 9 | 10 | namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities 11 | { 12 | public class LogFileTestBase : IISFunctionalTestBase 13 | { 14 | protected string _logFolderPath; 15 | 16 | public LogFileTestBase(ITestOutputHelper output = null) : base(output) 17 | { 18 | _logFolderPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); 19 | } 20 | public override void Dispose() 21 | { 22 | base.Dispose(); 23 | if (Directory.Exists(_logFolderPath)) 24 | { 25 | Directory.Delete(_logFolderPath, true); 26 | } 27 | } 28 | 29 | public string GetLogFileContent(IISDeploymentResult deploymentResult) 30 | { 31 | return Helpers.ReadAllTextFromFile(Helpers.GetExpectedLogName(deploymentResult, _logFolderPath), Logger); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/Common.Tests/Common.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/WebConfigHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Linq; 6 | using System.Xml.Linq; 7 | 8 | namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS 9 | { 10 | public static class WebConfigHelpers 11 | { 12 | public static Action AddOrModifyAspNetCoreSection(string key, string value) 13 | { 14 | return (element, _) => { 15 | element 16 | .Descendants("system.webServer") 17 | .Single() 18 | .GetOrAdd("aspNetCore") 19 | .SetAttributeValue(key, value); 20 | }; 21 | } 22 | 23 | public static Action AddOrModifyHandlerSection(string key, string value) 24 | { 25 | return (element, _) => 26 | { 27 | element 28 | .Descendants("system.webServer") 29 | .Single() 30 | .GetOrAdd("handlers") 31 | .GetOrAdd("add") 32 | .SetAttributeValue(key, value); 33 | }; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/IIS.Tests/HttpBodyControlFeatureTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Http.Features; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | using Xunit; 8 | 9 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 10 | { 11 | [SkipIfHostableWebCoreNotAvailable] 12 | [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, "https://github.com/aspnet/IISIntegration/issues/866")] 13 | public class ConnectionIdFeatureTests : StrictTestServerTests 14 | { 15 | [ConditionalFact] 16 | public async Task ProvidesConnectionId() 17 | { 18 | string connectionId = null; 19 | using (var testServer = await TestServer.Create(ctx => { 20 | var connectionIdFeature = ctx.Features.Get(); 21 | connectionId = connectionIdFeature.ConnectionId; 22 | return Task.CompletedTask; 23 | }, LoggerFactory)) 24 | { 25 | await testServer.HttpClient.GetStringAsync("/"); 26 | } 27 | 28 | Assert.NotNull(connectionId); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwarderconnection.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include "forwarderconnection.h" 5 | #include "exceptions.h" 6 | 7 | FORWARDER_CONNECTION::FORWARDER_CONNECTION( 8 | VOID 9 | ) : m_cRefs (1), 10 | m_hConnection (NULL) 11 | { 12 | } 13 | 14 | HRESULT 15 | FORWARDER_CONNECTION::Initialize( 16 | DWORD dwPort 17 | ) 18 | { 19 | RETURN_IF_FAILED(m_ConnectionKey.Initialize( dwPort )); 20 | m_hConnection = WinHttpConnect(g_hWinhttpSession, 21 | L"127.0.0.1", 22 | (USHORT) dwPort, 23 | 0); 24 | RETURN_LAST_ERROR_IF_NULL(m_hConnection); 25 | // 26 | // Since WinHttp will not emit WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING 27 | // when closing WebSocket handle on Win8. Register callback at Connect level as a workaround 28 | // 29 | RETURN_LAST_ERROR_IF (WinHttpSetStatusCallback(m_hConnection, 30 | FORWARDING_HANDLER::OnWinHttpCompletion, 31 | WINHTTP_CALLBACK_FLAG_HANDLES, 32 | NULL) == WINHTTP_INVALID_STATUS_CALLBACK); 33 | return S_OK; 34 | } 35 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/Core/IISServerSetupFilter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Hosting.Server; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace Microsoft.AspNetCore.Server.IIS.Core 11 | { 12 | internal class IISServerSetupFilter : IStartupFilter 13 | { 14 | private string _virtualPath; 15 | 16 | public IISServerSetupFilter(string virtualPath) 17 | { 18 | _virtualPath = virtualPath; 19 | } 20 | 21 | public Action Configure(Action next) 22 | { 23 | return app => 24 | { 25 | var server = app.ApplicationServices.GetService(); 26 | if (server?.GetType() != typeof(IISHttpServer)) 27 | { 28 | throw new InvalidOperationException("Application is running inside IIS process but is not configured to use IIS server."); 29 | } 30 | 31 | app.UsePathBase(_virtualPath); 32 | next(app); 33 | }; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IISIntegration/IISSetupFilter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | 9 | namespace Microsoft.AspNetCore.Server.IISIntegration 10 | { 11 | internal class IISSetupFilter : IStartupFilter 12 | { 13 | private readonly string _pairingToken; 14 | private readonly PathString _pathBase; 15 | private readonly bool _isWebsocketsSupported; 16 | 17 | internal IISSetupFilter(string pairingToken, PathString pathBase, bool isWebsocketsSupported) 18 | { 19 | _pairingToken = pairingToken; 20 | _pathBase = pathBase; 21 | _isWebsocketsSupported = isWebsocketsSupported; 22 | } 23 | 24 | public Action Configure(Action next) 25 | { 26 | return app => 27 | { 28 | app.UsePathBase(_pathBase); 29 | app.UseForwardedHeaders(); 30 | app.UseMiddleware(_pairingToken, _isWebsocketsSupported); 31 | next(app); 32 | }; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/RequestHandlerLib/AppOfflineTrackingApplication.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "application.h" 8 | #include "filewatcher.h" 9 | #include 10 | 11 | class AppOfflineTrackingApplication: public APPLICATION 12 | { 13 | public: 14 | AppOfflineTrackingApplication(const IHttpApplication& application) 15 | : APPLICATION(application), 16 | m_applicationPath(application.GetApplicationPhysicalPath()), 17 | m_fileWatcher(nullptr), 18 | m_fAppOfflineProcessed(false) 19 | { 20 | } 21 | 22 | ~AppOfflineTrackingApplication() override 23 | { 24 | if (m_fileWatcher) 25 | { 26 | m_fileWatcher->StopMonitor(); 27 | } 28 | }; 29 | 30 | HRESULT 31 | StartMonitoringAppOffline(); 32 | 33 | VOID 34 | StopInternal(bool fServerInitiated) override; 35 | 36 | virtual 37 | VOID 38 | OnAppOffline(); 39 | 40 | private: 41 | HRESULT 42 | StartMonitoringAppOflineImpl(); 43 | 44 | std::wstring m_applicationPath; 45 | std::unique_ptr m_fileWatcher; 46 | std::atomic_bool m_fAppOfflineProcessed; 47 | }; 48 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Inprocess/LargeResponseBodyTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Testing.xunit; 6 | using Xunit; 7 | 8 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 9 | { 10 | [Collection(IISTestSiteCollection.Name)] 11 | public class LargeResponseBodyTests 12 | { 13 | private readonly IISTestSiteFixture _fixture; 14 | 15 | public LargeResponseBodyTests(IISTestSiteFixture fixture) 16 | { 17 | _fixture = fixture; 18 | } 19 | 20 | [ConditionalTheory] 21 | [InlineData(65000)] 22 | [InlineData(1000000)] 23 | [InlineData(10000000)] 24 | [InlineData(100000000)] 25 | public async Task LargeResponseBodyTest_CheckAllResponseBodyBytesWritten(int query) 26 | { 27 | Assert.Equal(new string('a', query), await _fixture.Client.GetStringAsync($"/LargeResponseBody?length={query}")); 28 | } 29 | 30 | [ConditionalFact] 31 | public async Task LargeResponseBodyFromFile_CheckAllResponseBodyBytesWritten() 32 | { 33 | Assert.Equal(200000000, (await _fixture.Client.GetStringAsync($"/LargeResponseFile")).Length); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/IISLib/ntassert.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #ifdef _ASSERTE 7 | #undef _ASSERTE 8 | #endif 9 | 10 | #ifdef ASSERT 11 | #undef ASSERT 12 | #endif 13 | 14 | #if defined( DBG ) && DBG 15 | #define SX_ASSERT( _x ) ( (VOID)( ( ( _x ) ) ? TRUE : ( __annotation( L"Debug", L"AssertFail", L#_x ), DbgRaiseAssertionFailure(), FALSE ) ) ) 16 | #define SX_ASSERTMSG( _m, _x ) ( (VOID)( ( ( _x ) ) ? TRUE : ( __annotation( L"Debug", L"AssertFail", L##_m ), DbgRaiseAssertionFailure(), FALSE ) ) ) 17 | #define SX_VERIFY( _x ) SX_ASSERT( _x ) 18 | #define _ASSERTE( _x ) SX_ASSERT( _x ) 19 | #define ASSERT( _x ) SX_ASSERT( _x ) 20 | #define assert( _x ) SX_ASSERT( _x ) 21 | #define DBG_ASSERT( _x ) SX_ASSERT( _x ) 22 | #define DBG_REQUIRE( _x ) SX_ASSERT( _x ) 23 | #else 24 | #define SX_ASSERT( _x ) ( (VOID)0 ) 25 | #define SX_ASSERTMSG( _m, _x ) ( (VOID)0 ) 26 | #define SX_VERIFY( _x ) ( (VOID)( ( _x ) ? TRUE : FALSE ) ) 27 | #define _ASSERTE( _x ) ( (VOID)0 ) 28 | #define assert( _x ) ( (VOID)0 ) 29 | #define DBG_ASSERT( _x ) ( (VOID)0 ) 30 | #define DBG_REQUIRE( _x ) ((VOID)(_x)) 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Inprocess/HostingEnvironmentTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Testing.xunit; 8 | using Xunit; 9 | 10 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 11 | { 12 | [Collection(IISTestSiteCollection.Name)] 13 | public class HostingEnvironmentTests: FixtureLoggedTest 14 | { 15 | private readonly IISTestSiteFixture _fixture; 16 | 17 | public HostingEnvironmentTests(IISTestSiteFixture fixture): base(fixture) 18 | { 19 | _fixture = fixture; 20 | } 21 | 22 | [ConditionalFact] 23 | [RequiresIIS(IISCapability.ShutdownToken)] 24 | public async Task HostingEnvironmentIsCorrect() 25 | { 26 | Assert.Equal( 27 | $"ContentRootPath {_fixture.DeploymentResult.ContentRoot}" + Environment.NewLine + 28 | $"WebRootPath {_fixture.DeploymentResult.ContentRoot}\\wwwroot" + Environment.NewLine + 29 | $"CurrentDirectory {Path.GetDirectoryName(_fixture.DeploymentResult.HostProcess.MainModule.FileName)}", 30 | await _fixture.Client.GetStringAsync("/HostingEnvironment")); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/Core/IO/AsyncIOEngine.Flush.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.AspNetCore.Server.IIS.Core.IO 7 | { 8 | internal partial class AsyncIOEngine 9 | { 10 | internal class AsyncFlushOperation : AsyncIOOperation 11 | { 12 | private readonly AsyncIOEngine _engine; 13 | 14 | private IntPtr _requestHandler; 15 | 16 | public AsyncFlushOperation(AsyncIOEngine engine) 17 | { 18 | _engine = engine; 19 | } 20 | 21 | public void Initialize(IntPtr requestHandler) 22 | { 23 | _requestHandler = requestHandler; 24 | } 25 | 26 | protected override bool InvokeOperation(out int hr, out int bytes) 27 | { 28 | bytes = 0; 29 | hr = NativeMethods.HttpFlushResponseBytes(_requestHandler, out var fCompletionExpected); 30 | 31 | return !fCompletionExpected; 32 | } 33 | 34 | protected override void ResetOperation() 35 | { 36 | base.ResetOperation(); 37 | 38 | _requestHandler = default; 39 | _engine.ReturnOperation(this); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /benchmarks/IIS.Performance/FirstRequestConfig.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using BenchmarkDotNet.Columns; 5 | using BenchmarkDotNet.Configs; 6 | using BenchmarkDotNet.Diagnosers; 7 | using BenchmarkDotNet.Engines; 8 | using BenchmarkDotNet.Exporters; 9 | using BenchmarkDotNet.Jobs; 10 | using BenchmarkDotNet.Loggers; 11 | using BenchmarkDotNet.Toolchains.CsProj; 12 | using BenchmarkDotNet.Toolchains.DotNetCli; 13 | using BenchmarkDotNet.Validators; 14 | 15 | namespace BenchmarkDotNet.Attributes 16 | { 17 | internal class FirstRequestConfig : ManualConfig 18 | { 19 | public FirstRequestConfig() 20 | { 21 | Add(ConsoleLogger.Default); 22 | Add(MarkdownExporter.GitHub); 23 | 24 | Add(MemoryDiagnoser.Default); 25 | Add(StatisticColumn.OperationsPerSecond); 26 | Add(DefaultColumnProviders.Instance); 27 | 28 | Add(JitOptimizationsValidator.FailOnError); 29 | 30 | Add(Job.Core 31 | .With(CsProjCoreToolchain.From(NetCoreAppSettings.NetCoreApp21)) 32 | .With(new GcMode { Server = true }) 33 | .WithTargetCount(10) 34 | .WithInvocationCount(1) 35 | .WithUnrollFactor(1) 36 | .With(RunStrategy.ColdStart)); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/WebSites/OutOfProcessWebSite/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.IO; 5 | using System.Linq; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Logging; 8 | 9 | namespace TestSite 10 | { 11 | public static class Program 12 | { 13 | public static int Main(string[] args) 14 | { 15 | var mode = args.FirstOrDefault(); 16 | switch (mode) 17 | { 18 | case "CreateFile": 19 | File.WriteAllText(args[1], ""); 20 | return StartServer(); 21 | } 22 | 23 | return StartServer(); 24 | } 25 | 26 | private static int StartServer() 27 | { 28 | var host = new WebHostBuilder() 29 | .ConfigureLogging( 30 | (_, factory) => { 31 | factory.AddConsole(); 32 | factory.AddFilter("Console", level => level >= LogLevel.Information); 33 | }) 34 | .UseContentRoot(Directory.GetCurrentDirectory()) 35 | .UseIISIntegration() 36 | .UseStartup() 37 | .UseKestrel() 38 | .Build(); 39 | 40 | host.Run(); 41 | return 0; 42 | } 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/IISLib/ntassert.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #ifdef _ASSERTE 7 | #undef _ASSERTE 8 | #endif 9 | 10 | #ifdef ASSERT 11 | #undef ASSERT 12 | #endif 13 | 14 | #ifdef DEBUG 15 | #define DBG 1 16 | #endif 17 | 18 | #if defined( DBG ) && DBG 19 | #define SX_ASSERT( _x ) ( (VOID)( ( ( _x ) ) ? TRUE : ( __annotation( L"Debug", L"AssertFail", L#_x ), DbgRaiseAssertionFailure(), FALSE ) ) ) 20 | #define SX_ASSERTMSG( _m, _x ) ( (VOID)( ( ( _x ) ) ? TRUE : ( __annotation( L"Debug", L"AssertFail", L##_m ), DbgRaiseAssertionFailure(), FALSE ) ) ) 21 | #define SX_VERIFY( _x ) SX_ASSERT( _x ) 22 | #define _ASSERTE( _x ) SX_ASSERT( _x ) 23 | #define ASSERT( _x ) SX_ASSERT( _x ) 24 | #define assert( _x ) SX_ASSERT( _x ) 25 | #define DBG_ASSERT( _x ) SX_ASSERT( _x ) 26 | #define DBG_REQUIRE( _x ) SX_ASSERT( _x ) 27 | #else 28 | #define SX_ASSERT( _x ) ( (VOID)0 ) 29 | #define SX_ASSERTMSG( _m, _x ) ( (VOID)0 ) 30 | #define SX_VERIFY( _x ) ( (VOID)( ( _x ) ? TRUE : FALSE ) ) 31 | #define _ASSERTE( _x ) ( (VOID)0 ) 32 | #define assert( _x ) ( (VOID)0 ) 33 | #define DBG_ASSERT( _x ) ( (VOID)0 ) 34 | #define DBG_REQUIRE( _x ) ((VOID)(_x)) 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /test/IIS.Tests/TestServerTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | using Microsoft.Extensions.Logging.Testing; 8 | using Xunit; 9 | 10 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 11 | { 12 | [SkipIfHostableWebCoreNotAvailable] 13 | [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, "https://github.com/aspnet/IISIntegration/issues/866")] 14 | public class TestServerTest : StrictTestServerTests 15 | { 16 | [ConditionalFact] 17 | public async Task SingleProcessTestServer_HelloWorld() 18 | { 19 | var helloWorld = "Hello World"; 20 | var expectedPath = "/Path"; 21 | 22 | string path = null; 23 | using (var testServer = await TestServer.Create(ctx => 24 | { 25 | path = ctx.Request.Path.ToString(); 26 | return ctx.Response.WriteAsync(helloWorld); 27 | }, LoggerFactory)) 28 | { 29 | var result = await testServer.HttpClient.GetAsync(expectedPath); 30 | Assert.Equal(helloWorld, await result.Content.ReadAsStringAsync()); 31 | Assert.Equal(expectedPath, path); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/irequesthandler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | // 10 | // Pure abstract class 11 | // 12 | class IREQUEST_HANDLER 13 | { 14 | public: 15 | 16 | virtual 17 | REQUEST_NOTIFICATION_STATUS 18 | OnExecuteRequestHandler() = 0; 19 | 20 | virtual 21 | REQUEST_NOTIFICATION_STATUS 22 | OnAsyncCompletion( 23 | DWORD cbCompletion, 24 | HRESULT hrCompletionStatus 25 | ) = 0; 26 | 27 | virtual 28 | VOID 29 | NotifyDisconnect() noexcept(false) = 0; 30 | 31 | virtual 32 | ~IREQUEST_HANDLER( 33 | VOID 34 | ) = 0 { } 35 | 36 | virtual 37 | VOID 38 | ReferenceRequestHandler( 39 | VOID 40 | ) = 0; 41 | 42 | virtual 43 | VOID 44 | DereferenceRequestHandler( 45 | VOID 46 | ) = 0; 47 | }; 48 | 49 | 50 | struct IREQUEST_HANDLER_DELETER 51 | { 52 | void operator ()(IREQUEST_HANDLER* application) const 53 | { 54 | application->DereferenceRequestHandler(); 55 | } 56 | }; 57 | 58 | inline std::unique_ptr ReferenceRequestHandler(IREQUEST_HANDLER* handler) 59 | { 60 | handler->ReferenceRequestHandler(); 61 | return std::unique_ptr(handler); 62 | }; 63 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/InProcessRequestHandler/StartupExceptionApplication.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "InProcessApplicationBase.h" 7 | #include "ServerErrorHandler.h" 8 | #include "resource.h" 9 | 10 | class StartupExceptionApplication : public InProcessApplicationBase 11 | { 12 | public: 13 | StartupExceptionApplication( 14 | IHttpServer& pServer, 15 | IHttpApplication& pApplication, 16 | HINSTANCE moduleInstance, 17 | BOOL disableLogs, 18 | HRESULT hr) 19 | : m_disableLogs(disableLogs), 20 | m_HR(hr), 21 | m_moduleInstance(moduleInstance), 22 | InProcessApplicationBase(pServer, pApplication) 23 | { 24 | } 25 | 26 | ~StartupExceptionApplication() = default; 27 | 28 | HRESULT CreateHandler(IHttpContext *pHttpContext, IREQUEST_HANDLER ** pRequestHandler) 29 | { 30 | *pRequestHandler = new ServerErrorHandler(*pHttpContext, 500, 30, "Internal Server Error", m_HR, m_moduleInstance, m_disableLogs, IN_PROCESS_RH_STATIC_HTML); 31 | return S_OK; 32 | } 33 | 34 | std::string& 35 | GetStaticHtml500Content() 36 | { 37 | return html500Page; 38 | } 39 | 40 | private: 41 | std::string html500Page; 42 | BOOL m_disableLogs; 43 | HRESULT m_HR; 44 | HINSTANCE m_moduleInstance; 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/Core/IO/WebSocketsAsyncIOEngine.Initialize.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Microsoft.AspNetCore.Server.IIS.Core.IO 7 | { 8 | internal partial class WebSocketsAsyncIOEngine 9 | { 10 | internal class AsyncInitializeOperation : AsyncIOOperation 11 | { 12 | private readonly WebSocketsAsyncIOEngine _engine; 13 | 14 | private IntPtr _requestHandler; 15 | 16 | public AsyncInitializeOperation(WebSocketsAsyncIOEngine engine) 17 | { 18 | _engine = engine; 19 | } 20 | 21 | public void Initialize(IntPtr requestHandler) 22 | { 23 | _requestHandler = requestHandler; 24 | } 25 | 26 | protected override bool InvokeOperation(out int hr, out int bytes) 27 | { 28 | hr = NativeMethods.HttpFlushResponseBytes(_requestHandler, out var completionExpected); 29 | bytes = 0; 30 | return !completionExpected; 31 | } 32 | 33 | protected override void ResetOperation() 34 | { 35 | base.ResetOperation(); 36 | 37 | _requestHandler = default; 38 | _engine.ReturnOperation(this); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test/CommonLibTests/stdafx.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #define WIN32_LEAN_AND_MEAN 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include "stringa.h" 26 | #include "stringu.h" 27 | #include "dbgutil.h" 28 | #include "ahutil.h" 29 | #include "multisz.h" 30 | #include "multisza.h" 31 | #include "base64.h" 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "stringu.h" 39 | #include "stringa.h" 40 | #include "multisz.h" 41 | #include "dbgutil.h" 42 | #include "hashfn.h" 43 | 44 | #include "requesthandler_config.h" 45 | #include "hostfxr_utility.h" 46 | #include "config_utility.h" 47 | #include "environmentvariablehash.h" 48 | #include "iapplication.h" 49 | #include "debugutil.h" 50 | #include "requesthandler.h" 51 | #include "resources.h" 52 | #include "aspnetcore_msg.h" 53 | #include "Helpers.h" 54 | #include "GlobalVersionUtility.h" 55 | 56 | #undef assert // Macro redefinition in IISLib. 57 | #include "gtest/gtest.h" 58 | #include "fakeclasses.h" 59 | 60 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IISIntegration/IISOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | namespace Microsoft.AspNetCore.Builder 5 | { 6 | public class IISOptions 7 | { 8 | /// 9 | /// If true the middleware should set HttpContext.User. If false the middleware will only provide an 10 | /// identity when explicitly requested by the AuthenticationScheme. 11 | /// Note Windows Authentication must also be enabled in IIS for this to work. 12 | /// 13 | public bool AutomaticAuthentication { get; set; } = true; 14 | 15 | /// 16 | /// Sets the display name shown to users on login pages. The default is null. 17 | /// 18 | public string AuthenticationDisplayName { get; set; } 19 | 20 | /// 21 | /// Used to indicate if the authentication handler should be registered. This is only done if ANCM indicates 22 | /// IIS has a non-anonymous authentication enabled, or for back compat with ANCMs that did not provide this information. 23 | /// 24 | internal bool ForwardWindowsAuthentication { get; set; } = true; 25 | 26 | /// 27 | /// Populates the ITLSConnectionFeature if the MS-ASPNETCORE-CLIENTCERT request header is present. 28 | /// 29 | public bool ForwardClientCertificate { get; set; } = true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/Core/IISHttpContext.IHttpRequestIdentifierFeature.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using Microsoft.AspNetCore.Http.Features; 6 | 7 | namespace Microsoft.AspNetCore.Server.IIS.Core 8 | { 9 | internal partial class IISHttpContext : IHttpRequestIdentifierFeature 10 | { 11 | string IHttpRequestIdentifierFeature.TraceIdentifier 12 | { 13 | get 14 | { 15 | if (TraceIdentifier == null) 16 | { 17 | InitializeHttpRequestIdentifierFeature(); 18 | } 19 | 20 | return TraceIdentifier; 21 | } 22 | set => TraceIdentifier = value; 23 | } 24 | 25 | private unsafe void InitializeHttpRequestIdentifierFeature() 26 | { 27 | // Copied from WebListener 28 | // This is the base GUID used by HTTP.SYS for generating the activity ID. 29 | // HTTP.SYS overwrites the first 8 bytes of the base GUID with RequestId to generate ETW activity ID. 30 | // The requestId should be set by the NativeRequestContext 31 | var guid = new Guid(0xffcb4c93, 0xa57f, 0x453c, 0xb6, 0x3f, 0x84, 0x71, 0xc, 0x79, 0x67, 0xbb); 32 | *((ulong*)&guid) = RequestId; 33 | 34 | // TODO: Also make this not slow 35 | TraceIdentifier = guid.ToString(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/InProcessRequestHandler/ShuttingDownApplication.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "InProcessApplicationBase.h" 7 | 8 | class ShuttingDownHandler : public REQUEST_HANDLER 9 | { 10 | public: 11 | ShuttingDownHandler(IHttpContext* pContext) 12 | : REQUEST_HANDLER(*pContext), 13 | m_pContext(pContext) 14 | { 15 | } 16 | 17 | REQUEST_NOTIFICATION_STATUS ExecuteRequestHandler() override 18 | { 19 | return ServerShutdownMessage(m_pContext); 20 | } 21 | 22 | static REQUEST_NOTIFICATION_STATUS ServerShutdownMessage(IHttpContext * pContext) 23 | { 24 | pContext->GetResponse()->SetStatus(503, "Server has been shutdown", 0, HRESULT_FROM_WIN32(ERROR_SHUTDOWN_IN_PROGRESS)); 25 | return RQ_NOTIFICATION_FINISH_REQUEST; 26 | } 27 | private: 28 | IHttpContext * m_pContext; 29 | }; 30 | 31 | class ShuttingDownApplication : public InProcessApplicationBase 32 | { 33 | public: 34 | ShuttingDownApplication(IHttpServer& pHttpServer, IHttpApplication& pHttpApplication) 35 | : InProcessApplicationBase(pHttpServer, pHttpApplication) 36 | { 37 | } 38 | 39 | ~ShuttingDownApplication() = default; 40 | 41 | HRESULT CreateHandler(IHttpContext * pHttpContext, IREQUEST_HANDLER ** pRequestHandler) override 42 | { 43 | *pRequestHandler = new ShuttingDownHandler(pHttpContext); 44 | return S_OK; 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /test/IIS.BackwardsCompatibility.FunctionalTests/BackwardsCompatibilityTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Diagnostics; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | using Xunit; 8 | using Xunit.Sdk; 9 | 10 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 11 | { 12 | [Collection(IISTestSiteCollection.Name)] 13 | public class BackwardsCompatibilityTests : FixtureLoggedTest 14 | { 15 | private readonly IISTestSiteFixture _fixture; 16 | 17 | public BackwardsCompatibilityTests(IISTestSiteFixture fixture) : base(fixture) 18 | { 19 | _fixture = fixture; 20 | } 21 | 22 | [ConditionalFact] 23 | public async Task CheckBackwardsCompatibilityIsUsed() 24 | { 25 | 26 | var response = await _fixture.Client.GetAsync("/HelloWorld"); 27 | var handles = _fixture.DeploymentResult.HostProcess.Modules; 28 | 29 | foreach (ProcessModule handle in handles) 30 | { 31 | if (handle.ModuleName == "aspnetcorev2.dll") 32 | { 33 | Assert.Equal("12.2.18287.0", handle.FileVersionInfo.FileVersion); 34 | return; 35 | } 36 | } 37 | throw new XunitException($"Could not find aspnetcorev2.dll loaded in process {_fixture.DeploymentResult.HostProcess.ProcessName}"); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/IIS.ForwardsCompatibility.FunctionalTests/ForwardsCompatibilityTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Diagnostics; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | using Xunit; 8 | using Xunit.Sdk; 9 | 10 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 11 | { 12 | [Collection(IISTestSiteCollection.Name)] 13 | public class ForwardsCompatibilityTests : FixtureLoggedTest 14 | { 15 | private readonly IISTestSiteFixture _fixture; 16 | 17 | public ForwardsCompatibilityTests(IISTestSiteFixture fixture) : base(fixture) 18 | { 19 | _fixture = fixture; 20 | } 21 | 22 | [ConditionalFact] 23 | public async Task CheckForwardsCompatibilityIsUsed() 24 | { 25 | var response = await _fixture.Client.GetAsync("/HelloWorld"); 26 | var handles = _fixture.DeploymentResult.HostProcess.Modules; 27 | foreach (ProcessModule handle in handles) 28 | { 29 | if (handle.ModuleName == "aspnetcorev2_inprocess.dll") 30 | { 31 | Assert.Equal("12.2.18287.0", handle.FileVersionInfo.FileVersion); 32 | return; 33 | } 34 | } 35 | throw new XunitException($"Could not find aspnetcorev2_inprocess.dll loaded in process {_fixture.DeploymentResult.HostProcess.ProcessName}"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/WebSites/shared/WebSockets/TestStartup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Threading.Tasks; 4 | using Microsoft.AspNetCore.Builder; 5 | using Microsoft.AspNetCore.Http; 6 | 7 | namespace Microsoft.AspNetCore.IISIntegration.FunctionalTests 8 | { 9 | public static class TestStartup 10 | { 11 | public static void Register(IApplicationBuilder app, object startup) 12 | { 13 | var type = startup.GetType(); 14 | foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) 15 | { 16 | var parameters = method.GetParameters(); 17 | if (method.Name != "Configure" && 18 | parameters.Length == 1) 19 | { 20 | Action appfunc = null; 21 | if (parameters[0].ParameterType == typeof(IApplicationBuilder)) 22 | { 23 | appfunc = innerAppBuilder => method.Invoke(startup, new[] { innerAppBuilder }); 24 | } 25 | else if (parameters[0].ParameterType == typeof(HttpContext)) 26 | { 27 | appfunc = innerAppBuilder => innerAppBuilder.Run(ctx => (Task)method.Invoke(startup, new[] { ctx })); 28 | } 29 | 30 | if (appfunc != null) 31 | { 32 | app.Map("/" + method.Name, appfunc); 33 | } 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/AspNetCore/src/forwarderconnection.cxx: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include "precomp.hxx" 5 | 6 | FORWARDER_CONNECTION::FORWARDER_CONNECTION( 7 | VOID 8 | ) : m_cRefs (1), 9 | m_hConnection (NULL) 10 | { 11 | } 12 | 13 | HRESULT 14 | FORWARDER_CONNECTION::Initialize( 15 | DWORD dwPort 16 | ) 17 | { 18 | HRESULT hr = S_OK; 19 | 20 | hr = m_ConnectionKey.Initialize( dwPort ); 21 | if ( FAILED( hr ) ) 22 | { 23 | goto Finished; 24 | } 25 | 26 | m_hConnection = WinHttpConnect(FORWARDING_HANDLER::sm_hSession, 27 | L"127.0.0.1", 28 | (USHORT) dwPort, 29 | 0); 30 | if (m_hConnection == NULL) 31 | { 32 | hr = HRESULT_FROM_WIN32(GetLastError()); 33 | goto Finished; 34 | } 35 | 36 | // 37 | // Since WinHttp will not emit WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING 38 | // when closing WebSocket handle on Win8. Register callback at Connect level as a workaround 39 | // 40 | if (WinHttpSetStatusCallback(m_hConnection, 41 | FORWARDING_HANDLER::OnWinHttpCompletion, 42 | WINHTTP_CALLBACK_FLAG_HANDLES, 43 | NULL) == WINHTTP_INVALID_STATUS_CALLBACK) 44 | { 45 | hr = HRESULT_FROM_WIN32(GetLastError()); 46 | goto Finished; 47 | } 48 | 49 | Finished: 50 | 51 | return hr; 52 | } -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/AspNetCore/Inc/proxymodule.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "forwardinghandler.h" 7 | 8 | class CProxyModule : public CHttpModule 9 | { 10 | public: 11 | 12 | CProxyModule(); 13 | 14 | ~CProxyModule(); 15 | 16 | void * operator new(size_t size, IModuleAllocator * pPlacement) 17 | { 18 | return pPlacement->AllocateMemory(static_cast(size)); 19 | } 20 | 21 | VOID 22 | operator delete( 23 | void * 24 | ) 25 | { 26 | } 27 | 28 | __override 29 | REQUEST_NOTIFICATION_STATUS 30 | OnExecuteRequestHandler( 31 | IHttpContext * pHttpContext, 32 | IHttpEventProvider * pProvider 33 | ); 34 | 35 | __override 36 | REQUEST_NOTIFICATION_STATUS 37 | OnAsyncCompletion( 38 | IHttpContext * pHttpContext, 39 | DWORD dwNotification, 40 | BOOL fPostNotification, 41 | IHttpEventProvider * pProvider, 42 | IHttpCompletionInfo * pCompletionInfo 43 | ); 44 | 45 | private: 46 | 47 | FORWARDING_HANDLER * m_pHandler; 48 | }; 49 | 50 | class CProxyModuleFactory : public IHttpModuleFactory 51 | { 52 | public: 53 | HRESULT 54 | GetHttpModule( 55 | CHttpModule ** ppModule, 56 | IModuleAllocator * pAllocator 57 | ); 58 | 59 | VOID 60 | Terminate(); 61 | }; -------------------------------------------------------------------------------- /test/WebSites/OutOfProcessWebSite/OutOfProcessWebSite.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $(StandardTestTfms) 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/HttpContextExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Http.Features; 6 | 7 | namespace Microsoft.AspNetCore.Server.IIS 8 | { 9 | /// 10 | /// Extensions to that enable access to IIS features. 11 | /// 12 | public static class HttpContextExtensions 13 | { 14 | /// 15 | /// Gets the value of a server variable for the current request. 16 | /// 17 | /// The http context for the request. 18 | /// The name of the variable. 19 | /// 20 | /// null if the feature does not support the feature. 21 | /// May return null or empty if the variable does not exist or is not set. 22 | /// 23 | /// 24 | /// For a list of common server variables available in IIS, see http://go.microsoft.com/fwlink/?LinkId=52471. 25 | /// 26 | public static string GetIISServerVariable(this HttpContext context, string variableName) 27 | { 28 | var feature = context.Features.Get(); 29 | 30 | if (feature == null) 31 | { 32 | return null; 33 | } 34 | 35 | return feature[variableName]; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/DisconnectHandler.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #include "DisconnectHandler.h" 5 | #include "exceptions.h" 6 | #include "proxymodule.h" 7 | #include "SRWExclusiveLock.h" 8 | 9 | void DisconnectHandler::NotifyDisconnect() 10 | { 11 | try 12 | { 13 | std::unique_ptr pHandler; 14 | { 15 | SRWExclusiveLock lock(m_handlerLock); 16 | m_pHandler.swap(pHandler); 17 | m_disconnectFired = true; 18 | } 19 | 20 | if (pHandler != nullptr) 21 | { 22 | pHandler->NotifyDisconnect(); 23 | } 24 | } 25 | catch (...) 26 | { 27 | OBSERVE_CAUGHT_EXCEPTION(); 28 | } 29 | } 30 | 31 | void DisconnectHandler::CleanupStoredContext() noexcept 32 | { 33 | delete this; 34 | } 35 | 36 | void DisconnectHandler::SetHandler(std::unique_ptr handler) 37 | { 38 | IREQUEST_HANDLER* pHandler = nullptr; 39 | { 40 | SRWExclusiveLock lock(m_handlerLock); 41 | 42 | handler.swap(m_pHandler); 43 | pHandler = m_pHandler.get(); 44 | } 45 | 46 | assert(pHandler != nullptr); 47 | 48 | if (pHandler != nullptr && (m_disconnectFired || m_pHttpConnection != nullptr && !m_pHttpConnection->IsConnected())) 49 | { 50 | pHandler->NotifyDisconnect(); 51 | } 52 | } 53 | 54 | void DisconnectHandler::RemoveHandler() noexcept 55 | { 56 | m_pHandler = nullptr; 57 | } 58 | -------------------------------------------------------------------------------- /samples/NativeIISSample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": true, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:5762/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "ANCM IIS Express": { 12 | "commandName": "Executable", 13 | "executablePath": "$(IISExpressPath)", 14 | "commandLineArgs": "$(IISExpressArguments)", 15 | "environmentVariables": { 16 | "IIS_SITE_PATH": "$(MSBuildThisFileDirectory)", 17 | "ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)", 18 | "ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)", 19 | "ANCM_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)", 20 | "LAUNCHER_ARGS": "$(TargetPath)", 21 | "ASPNETCORE_ENVIRONMENT": "Development", 22 | "LAUNCHER_PATH": "$(DotNetPath)", 23 | "ASPNETCORE_MODULE_DEBUG": "console" 24 | } 25 | }, 26 | "ANCM IIS": { 27 | "commandName": "Executable", 28 | "executablePath": "$(IISPath)", 29 | "commandLineArgs": "$(IISArguments)", 30 | "environmentVariables": { 31 | "IIS_SITE_PATH": "$(MSBuildThisFileDirectory)", 32 | "ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)", 33 | "ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)", 34 | "ASPNETCORE_MODULE_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)", 35 | "LAUNCHER_ARGS": "$(TargetPath)", 36 | "ASPNETCORE_ENVIRONMENT": "Development", 37 | "LAUNCHER_PATH": "$(DotNetPath)", 38 | "ASPNETCORE_MODULE_DEBUG": "console" 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /version.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3 4 | 0 5 | 0 6 | $(DotNetMajorVersion).$(DotNetMinorVersion).$(DotNetPatchVersion) 7 | 13 8 | $(DotNetMinorVersion) 9 | $(DotNetPatchVersion) 10 | alpha1 11 | ancm-oob 12 | $(VersionPrefix) 13 | $(VersionPrefix)-$(VersionSuffix)-final 14 | t000 15 | a- 16 | $(FeatureBranchVersionPrefix)$(VersionSuffix)-$([System.Text.RegularExpressions.Regex]::Replace('$(FeatureBranchVersionSuffix)', '[^\w-]', '-')) 17 | $(VersionSuffix)-$(BuildNumber) 18 | 2.0.0 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/WebSites/InProcessWebSite/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": true, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:5762/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "ANCM IIS Express": { 12 | "commandName": "Executable", 13 | "executablePath": "$(IISExpressPath)", 14 | "commandLineArgs": "$(IISExpressArguments)", 15 | "environmentVariables": { 16 | "IIS_SITE_PATH": "$(MSBuildThisFileDirectory)", 17 | "ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)", 18 | "ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)", 19 | "ANCM_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)", 20 | "LAUNCHER_ARGS": "$(TargetPath)", 21 | "ASPNETCORE_ENVIRONMENT": "Development", 22 | "LAUNCHER_PATH": "$(DotNetPath)", 23 | "ASPNETCORE_MODULE_DEBUG": "console" 24 | } 25 | }, 26 | "ANCM IIS": { 27 | "commandName": "Executable", 28 | "executablePath": "$(IISPath)", 29 | "commandLineArgs": "$(IISArguments)", 30 | "environmentVariables": { 31 | "IIS_SITE_PATH": "$(MSBuildThisFileDirectory)", 32 | "ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)", 33 | "ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)", 34 | "ASPNETCORE_MODULE_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)", 35 | "LAUNCHER_ARGS": "$(TargetPath)", 36 | "ASPNETCORE_ENVIRONMENT": "Development", 37 | "LAUNCHER_PATH": "$(DotNetPath)", 38 | "ASPNETCORE_MODULE_DEBUG": "console" 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test/WebSites/StressTestWebSite/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": true, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:5762/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "ANCM IIS Express": { 12 | "commandName": "Executable", 13 | "executablePath": "$(IISExpressPath)", 14 | "commandLineArgs": "$(IISExpressArguments)", 15 | "environmentVariables": { 16 | "IIS_SITE_PATH": "$(MSBuildThisFileDirectory)", 17 | "ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)", 18 | "ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)", 19 | "ANCM_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)", 20 | "LAUNCHER_ARGS": "$(TargetPath)", 21 | "ASPNETCORE_ENVIRONMENT": "Development", 22 | "LAUNCHER_PATH": "$(DotNetPath)", 23 | "ASPNETCORE_MODULE_DEBUG": "console" 24 | } 25 | }, 26 | "ANCM IIS": { 27 | "commandName": "Executable", 28 | "executablePath": "$(IISPath)", 29 | "commandLineArgs": "$(IISArguments)", 30 | "environmentVariables": { 31 | "IIS_SITE_PATH": "$(MSBuildThisFileDirectory)", 32 | "ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)", 33 | "ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)", 34 | "ASPNETCORE_MODULE_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)", 35 | "LAUNCHER_ARGS": "$(TargetPath)", 36 | "ASPNETCORE_ENVIRONMENT": "Development", 37 | "LAUNCHER_PATH": "$(DotNetPath)", 38 | "ASPNETCORE_MODULE_DEBUG": "console" 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test/WebSites/OutOfProcessWebSite/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": true, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:5762/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "ANCM IIS Express": { 12 | "commandName": "Executable", 13 | "executablePath": "$(IISExpressPath)", 14 | "commandLineArgs": "$(IISExpressArguments)", 15 | "environmentVariables": { 16 | "IIS_SITE_PATH": "$(MSBuildThisFileDirectory)", 17 | "ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)", 18 | "ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)", 19 | "ANCM_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)", 20 | "LAUNCHER_ARGS": "$(TargetPath)", 21 | "ASPNETCORE_ENVIRONMENT": "Development", 22 | "LAUNCHER_PATH": "$(DotNetPath)", 23 | "ASPNETCORE_MODULE_DEBUG": "console" 24 | } 25 | }, 26 | "ANCM IIS": { 27 | "commandName": "Executable", 28 | "executablePath": "$(IISPath)", 29 | "commandLineArgs": "$(IISArguments)", 30 | "environmentVariables": { 31 | "IIS_SITE_PATH": "$(MSBuildThisFileDirectory)", 32 | "ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)", 33 | "ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)", 34 | "ASPNETCORE_MODULE_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)", 35 | "LAUNCHER_ARGS": "$(TargetPath)", 36 | "ASPNETCORE_ENVIRONMENT": "Development", 37 | "LAUNCHER_PATH": "$(DotNetPath)", 38 | "ASPNETCORE_MODULE_DEBUG": "console" 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/applicationmanager.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include "applicationinfo.h" 7 | #include "multisz.h" 8 | #include "exceptions.h" 9 | #include 10 | 11 | // 12 | // This class will manage the lifecycle of all Asp.Net Core applciation 13 | // It should be global singleton. 14 | // Should always call GetInstance to get the object instance 15 | // 16 | 17 | 18 | class APPLICATION_MANAGER 19 | { 20 | public: 21 | 22 | HRESULT 23 | GetOrCreateApplicationInfo( 24 | _In_ IHttpContext& pHttpContext, 25 | _Out_ std::shared_ptr& ppApplicationInfo 26 | ); 27 | 28 | HRESULT 29 | RecycleApplicationFromManager( 30 | _In_ LPCWSTR pszApplicationId 31 | ); 32 | 33 | VOID 34 | ShutDown(); 35 | 36 | APPLICATION_MANAGER(HMODULE hModule, IHttpServer& pHttpServer) : 37 | m_pApplicationInfoHash(NULL), 38 | m_fDebugInitialize(FALSE), 39 | m_pHttpServer(pHttpServer), 40 | m_handlerResolver(hModule, pHttpServer) 41 | { 42 | InitializeSRWLock(&m_srwLock); 43 | } 44 | 45 | private: 46 | 47 | std::unordered_map> m_pApplicationInfoHash; 48 | SRWLOCK m_srwLock {}; 49 | BOOL m_fDebugInitialize; 50 | IHttpServer &m_pHttpServer; 51 | HandlerResolver m_handlerResolver; 52 | }; 53 | -------------------------------------------------------------------------------- /test/WebSites/InProcessForwardsCompatWebSite/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": true, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:5762/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "ANCM IIS Express": { 12 | "commandName": "Executable", 13 | "executablePath": "$(IISExpressPath)", 14 | "commandLineArgs": "$(IISExpressArguments)", 15 | "environmentVariables": { 16 | "IIS_SITE_PATH": "$(MSBuildThisFileDirectory)", 17 | "ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)", 18 | "ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)", 19 | "ANCM_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)", 20 | "LAUNCHER_ARGS": "$(TargetPath)", 21 | "ASPNETCORE_ENVIRONMENT": "Development", 22 | "LAUNCHER_PATH": "$(DotNetPath)", 23 | "ASPNETCORE_MODULE_DEBUG": "console" 24 | } 25 | }, 26 | "ANCM IIS": { 27 | "commandName": "Executable", 28 | "executablePath": "$(IISPath)", 29 | "commandLineArgs": "$(IISArguments)", 30 | "environmentVariables": { 31 | "IIS_SITE_PATH": "$(MSBuildThisFileDirectory)", 32 | "ANCM_PATH": "$(AspNetCoreModuleV1ShimDll)", 33 | "ANCMV2_PATH": "$(AspNetCoreModuleV2ShimDll)", 34 | "ASPNETCORE_MODULE_OUTOFPROCESS_HANDLER": "$(AspNetCoreModuleV2OutOfProcessHandlerDll)", 35 | "LAUNCHER_ARGS": "$(TargetPath)", 36 | "ASPNETCORE_ENVIRONMENT": "Development", 37 | "LAUNCHER_PATH": "$(DotNetPath)", 38 | "ASPNETCORE_MODULE_DEBUG": "console" 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/IISLib/base64.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #ifndef _BASE64_H_ 5 | #define _BASE64_H_ 6 | 7 | DWORD 8 | Base64Encode( 9 | __in_bcount( cbDecodedBufferSize ) VOID * pDecodedBuffer, 10 | IN DWORD cbDecodedBufferSize, 11 | __out_ecount_opt( cchEncodedStringSize ) PWSTR pszEncodedString, 12 | IN DWORD cchEncodedStringSize, 13 | __out_opt DWORD * pcchEncoded 14 | ); 15 | 16 | DWORD 17 | Base64Decode( 18 | __in PCWSTR pszEncodedString, 19 | __out_opt VOID * pDecodeBuffer, 20 | __in DWORD cbDecodeBufferSize, 21 | __out_opt DWORD * pcbDecoded 22 | ); 23 | 24 | DWORD 25 | Base64Encode( 26 | __in_bcount( cbDecodedBufferSize ) VOID * pDecodedBuffer, 27 | IN DWORD cbDecodedBufferSize, 28 | __out_ecount_opt( cchEncodedStringSize ) PSTR pszEncodedString, 29 | IN DWORD cchEncodedStringSize, 30 | __out_opt DWORD * pcchEncoded 31 | ); 32 | 33 | DWORD 34 | Base64Decode( 35 | __in PCSTR pszEncodedString, 36 | __out_opt VOID * pDecodeBuffer, 37 | __in DWORD cbDecodeBufferSize, 38 | __out_opt DWORD * pcbDecoded 39 | ); 40 | 41 | #endif // _BASE64_HXX_ 42 | 43 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/IISLib/base64.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #ifndef _BASE64_H_ 5 | #define _BASE64_H_ 6 | 7 | DWORD 8 | Base64Encode( 9 | __in_bcount( cbDecodedBufferSize ) VOID * pDecodedBuffer, 10 | IN DWORD cbDecodedBufferSize, 11 | __out_ecount_opt( cchEncodedStringSize ) PWSTR pszEncodedString, 12 | IN DWORD cchEncodedStringSize, 13 | __out_opt DWORD * pcchEncoded 14 | ); 15 | 16 | DWORD 17 | Base64Decode( 18 | __in PCWSTR pszEncodedString, 19 | __out_opt VOID * pDecodeBuffer, 20 | __in DWORD cbDecodeBufferSize, 21 | __out_opt DWORD * pcbDecoded 22 | ); 23 | 24 | DWORD 25 | Base64Encode( 26 | __in_bcount( cbDecodedBufferSize ) VOID * pDecodedBuffer, 27 | IN DWORD cbDecodedBufferSize, 28 | __out_ecount_opt( cchEncodedStringSize ) PSTR pszEncodedString, 29 | IN DWORD cchEncodedStringSize, 30 | __out_opt DWORD * pcchEncoded 31 | ); 32 | 33 | DWORD 34 | Base64Decode( 35 | __in PCSTR pszEncodedString, 36 | __out_opt VOID * pDecodeBuffer, 37 | __in DWORD cbDecodeBufferSize, 38 | __out_opt DWORD * pcbDecoded 39 | ); 40 | 41 | #endif // _BASE64_HXX_ 42 | 43 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeploymentResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Diagnostics; 5 | using System.Net.Http; 6 | using System.Threading; 7 | using Microsoft.Extensions.Logging; 8 | 9 | namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS 10 | { 11 | public class IISDeploymentResult : DeploymentResult 12 | { 13 | public ILogger Logger { get; set; } 14 | public Process HostProcess { get; } 15 | 16 | public IISDeploymentResult(ILoggerFactory loggerFactory, 17 | IISDeploymentParameters deploymentParameters, 18 | string applicationBaseUri, 19 | string contentRoot, 20 | CancellationToken hostShutdownToken, 21 | Process hostProcess) 22 | : base(loggerFactory, 23 | deploymentParameters, 24 | applicationBaseUri, 25 | contentRoot, 26 | hostShutdownToken) 27 | { 28 | HostProcess = hostProcess; 29 | Logger = loggerFactory.CreateLogger(deploymentParameters.SiteName); 30 | HttpClient = CreateClient(new HttpClientHandler()); 31 | } 32 | 33 | public HttpClient CreateClient(HttpMessageHandler messageHandler) 34 | { 35 | return new HttpClient(new LoggingHandler(messageHandler, Logger)) 36 | { 37 | BaseAddress = base.HttpClient.BaseAddress 38 | }; 39 | } 40 | 41 | public new HttpClient HttpClient { get; set; } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/StringHelpers.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #include "StringHelpers.h" 5 | #include "exceptions.h" 6 | 7 | bool ends_with(const std::wstring &source, const std::wstring &suffix, bool ignoreCase) 8 | { 9 | if (source.length() < suffix.length()) 10 | { 11 | return false; 12 | } 13 | 14 | const auto offset = source.length() - suffix.length(); 15 | return CSTR_EQUAL == CompareStringOrdinal(source.c_str() + offset, static_cast(suffix.length()), suffix.c_str(), static_cast(suffix.length()), ignoreCase); 16 | } 17 | 18 | bool equals_ignore_case(const std::wstring& s1, const std::wstring& s2) 19 | { 20 | return CSTR_EQUAL == CompareStringOrdinal(s1.c_str(), static_cast(s1.length()), s2.c_str(), static_cast(s2.length()), true); 21 | } 22 | 23 | std::wstring to_wide_string(const std::string &source, const unsigned int codePage) 24 | { 25 | // MultiByteToWideChar returns 0 on failure, which is also the same return value 26 | // for empty strings. Preemptive return. 27 | if (source.length() == 0) 28 | { 29 | return L""; 30 | } 31 | 32 | std::wstring destination; 33 | 34 | int nChars = MultiByteToWideChar(codePage, 0, source.data(), static_cast(source.length()), NULL, 0); 35 | THROW_LAST_ERROR_IF(nChars == 0); 36 | 37 | destination.resize(nChars); 38 | 39 | nChars = MultiByteToWideChar(codePage, 0, source.data(), static_cast(source.length()), destination.data(), nChars); 40 | THROW_LAST_ERROR_IF(nChars == 0); 41 | 42 | return destination; 43 | } 44 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/OutOfProcessRequestHandler/outprocessapplication.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #pragma once 5 | 6 | #include "AppOfflineTrackingApplication.h" 7 | 8 | class OUT_OF_PROCESS_APPLICATION : public AppOfflineTrackingApplication 9 | { 10 | enum WEBSOCKET_STATUS 11 | { 12 | WEBSOCKET_UNKNOWN = 0, 13 | WEBSOCKET_NOT_SUPPORTED, 14 | WEBSOCKET_SUPPORTED, 15 | }; 16 | 17 | public: 18 | OUT_OF_PROCESS_APPLICATION( 19 | IHttpApplication& pApplication, 20 | std::unique_ptr pConfig); 21 | 22 | __override 23 | ~OUT_OF_PROCESS_APPLICATION() override; 24 | 25 | HRESULT 26 | Initialize(); 27 | 28 | HRESULT 29 | GetProcess( 30 | _Out_ SERVER_PROCESS **ppServerProcess 31 | ); 32 | 33 | __override 34 | VOID 35 | StopInternal(bool fServerInitiated) 36 | override; 37 | 38 | __override 39 | HRESULT 40 | CreateHandler( 41 | _In_ IHttpContext *pHttpContext, 42 | _Out_ IREQUEST_HANDLER **pRequestHandler) 43 | override; 44 | 45 | BOOL 46 | QueryWebsocketStatus() 47 | const; 48 | 49 | REQUESTHANDLER_CONFIG* QueryConfig() 50 | { 51 | return m_pConfig.get(); 52 | } 53 | 54 | private: 55 | 56 | VOID SetWebsocketStatus(IHttpContext *pHttpContext); 57 | 58 | PROCESS_MANAGER * m_pProcessManager; 59 | IHttpServer *m_pHttpServer; 60 | 61 | WEBSOCKET_STATUS m_fWebSocketSupported; 62 | std::unique_ptr m_pConfig; 63 | }; 64 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/ServerErrorApplication.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | #include "PollingAppOfflineApplication.h" 6 | #include "requesthandler.h" 7 | #include "ServerErrorHandler.h" 8 | 9 | class ServerErrorApplication : public PollingAppOfflineApplication 10 | { 11 | public: 12 | ServerErrorApplication(const IHttpApplication& pApplication, HRESULT hr, HINSTANCE moduleInstance) 13 | : ServerErrorApplication(pApplication, hr, moduleInstance, true /* disableStartupPage*/, 0 /* page */) 14 | { 15 | } 16 | 17 | ServerErrorApplication(const IHttpApplication& pApplication, HRESULT hr, HINSTANCE moduleInstance, bool disableStartupPage, int page) 18 | : m_HR(hr), 19 | m_disableStartupPage(disableStartupPage), 20 | m_page(page), 21 | m_moduleInstance(moduleInstance), 22 | PollingAppOfflineApplication(pApplication, PollingAppOfflineApplicationMode::StopWhenAdded) 23 | { 24 | } 25 | 26 | ~ServerErrorApplication() = default; 27 | 28 | HRESULT CreateHandler(IHttpContext *pHttpContext, IREQUEST_HANDLER ** pRequestHandler) override 29 | { 30 | auto handler = std::make_unique(*pHttpContext, 500ui16, 0ui16, "Internal Server Error", m_HR, m_moduleInstance, m_disableStartupPage, m_page); 31 | *pRequestHandler = handler.release(); 32 | return S_OK; 33 | } 34 | 35 | HRESULT OnAppOfflineFound() noexcept override { return S_OK; } 36 | private: 37 | HRESULT m_HR; 38 | bool m_disableStartupPage; 39 | int m_page; 40 | HINSTANCE m_moduleInstance; 41 | }; 42 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/AspNetCore/aspnetcore_msg.mc: -------------------------------------------------------------------------------- 1 | ;/*++ 2 | ; 3 | ; Copyright (c) .NET Foundation. All rights reserved. 4 | ; Licensed under the MIT License. See License.txt in the project root for license information. 5 | ; 6 | ;Module Name: 7 | ; 8 | ; aspnetcore_msg.mc 9 | ; 10 | ;Abstract: 11 | ; 12 | ; Asp.Net Core Module localizable messages. 13 | ; 14 | ;--*/ 15 | ; 16 | ; 17 | ;#ifndef _ASPNETCORE_MSG_H_ 18 | ;#define _ASPNETCORE_MSG_H_ 19 | ; 20 | 21 | SeverityNames=(Success=0x0 22 | Informational=0x1 23 | Warning=0x2 24 | Error=0x3 25 | ) 26 | 27 | MessageIdTypedef=DWORD 28 | 29 | Messageid=1000 30 | SymbolicName=ASPNETCORE_EVENT_PROCESS_START_ERROR 31 | Language=English 32 | %1 33 | . 34 | 35 | Messageid=1001 36 | SymbolicName=ASPNETCORE_EVENT_PROCESS_START_SUCCESS 37 | Language=English 38 | %1 39 | . 40 | 41 | Messageid=1002 42 | SymbolicName=ASPNETCORE_EVENT_PROCESS_CRASH 43 | Language=English 44 | %1 45 | . 46 | 47 | Messageid=1003 48 | SymbolicName=ASPNETCORE_EVENT_RAPID_FAIL_COUNT_EXCEEDED 49 | Language=English 50 | %1 51 | . 52 | 53 | Messageid=1004 54 | SymbolicName=ASPNETCORE_EVENT_CONFIG_ERROR 55 | Language=English 56 | %1 57 | . 58 | 59 | Messageid=1005 60 | SymbolicName=ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE 61 | Language=English 62 | %1 63 | . 64 | 65 | Messageid=1006 66 | SymbolicName=ASPNETCORE_EVENT_SENT_SHUTDOWN_HTTP_REQUEST 67 | Language=English 68 | %1 69 | . 70 | 71 | Messageid=1012 72 | SymbolicName=ASPNETCORE_EVENT_RECYCLE_APPOFFLINE 73 | Language=English 74 | %1 75 | . 76 | 77 | Messageid=1030 78 | SymbolicName=ASPNETCORE_EVENT_PROCESS_SHUTDOWN 79 | Language=English 80 | %1 81 | . 82 | 83 | ; 84 | ;#endif // _ASPNETCORE_MODULE_MSG_H_ 85 | ; 86 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/IISLib/macros.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #ifndef _MACROS_H 5 | #define _MACROS_H 6 | 7 | // 8 | // The DIFF macro should be used around an expression involving pointer 9 | // subtraction. The expression passed to DIFF is cast to a size_t type, 10 | // allowing the result to be easily assigned to any 32-bit variable or 11 | // passed to a function expecting a 32-bit argument. 12 | // 13 | 14 | #define DIFF(x) ((size_t)(x)) 15 | 16 | // Change a hexadecimal digit to its numerical equivalent 17 | #define TOHEX( ch ) \ 18 | ((ch) > L'9' ? \ 19 | (ch) >= L'a' ? \ 20 | (ch) - L'a' + 10 : \ 21 | (ch) - L'A' + 10 \ 22 | : (ch) - L'0') 23 | 24 | 25 | // Change a number to its Hexadecimal equivalent 26 | 27 | #define TODIGIT( nDigit ) \ 28 | (CHAR)((nDigit) > 9 ? \ 29 | (nDigit) - 10 + 'A' \ 30 | : (nDigit) + '0') 31 | 32 | 33 | inline int 34 | SAFEIsSpace(UCHAR c) 35 | { 36 | return isspace( c ); 37 | } 38 | 39 | inline int 40 | SAFEIsAlNum(UCHAR c) 41 | { 42 | return isalnum( c ); 43 | } 44 | 45 | inline int 46 | SAFEIsAlpha(UCHAR c) 47 | { 48 | return isalpha( c ); 49 | } 50 | 51 | inline int 52 | SAFEIsXDigit(UCHAR c) 53 | { 54 | return isxdigit( c ); 55 | } 56 | 57 | inline int 58 | SAFEIsDigit(UCHAR c) 59 | { 60 | return isdigit( c ); 61 | } 62 | 63 | #endif // _MACROS_H 64 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/IISLib/macros.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #ifndef _MACROS_H 5 | #define _MACROS_H 6 | 7 | // 8 | // The DIFF macro should be used around an expression involving pointer 9 | // subtraction. The expression passed to DIFF is cast to a size_t type, 10 | // allowing the result to be easily assigned to any 32-bit variable or 11 | // passed to a function expecting a 32-bit argument. 12 | // 13 | 14 | #define DIFF(x) ((size_t)(x)) 15 | 16 | // Change a hexadecimal digit to its numerical equivalent 17 | #define TOHEX( ch ) \ 18 | ((ch) > L'9' ? \ 19 | (ch) >= L'a' ? \ 20 | (ch) - L'a' + 10 : \ 21 | (ch) - L'A' + 10 \ 22 | : (ch) - L'0') 23 | 24 | 25 | // Change a number to its Hexadecimal equivalent 26 | 27 | #define TODIGIT( nDigit ) \ 28 | (CHAR)((nDigit) > 9 ? \ 29 | (nDigit) - 10 + 'A' \ 30 | : (nDigit) + '0') 31 | 32 | 33 | inline int 34 | SAFEIsSpace(UCHAR c) 35 | { 36 | return isspace( c ); 37 | } 38 | 39 | inline int 40 | SAFEIsAlNum(UCHAR c) 41 | { 42 | return isalnum( c ); 43 | } 44 | 45 | inline int 46 | SAFEIsAlpha(UCHAR c) 47 | { 48 | return isalpha( c ); 49 | } 50 | 51 | inline int 52 | SAFEIsXDigit(UCHAR c) 53 | { 54 | return isxdigit( c ); 55 | } 56 | 57 | inline int 58 | SAFEIsDigit(UCHAR c) 59 | { 60 | return isdigit( c ); 61 | } 62 | 63 | #endif // _MACROS_H 64 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/XElementExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Linq; 6 | using System.Xml.Linq; 7 | 8 | namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS 9 | { 10 | public static class XElementExtensions 11 | { 12 | public static XElement RequiredElement(this XElement element, string name) 13 | { 14 | var existing = element.Element(name); 15 | if (existing == null) 16 | { 17 | throw new InvalidOperationException($"Element with name {name} not found in {element}"); 18 | } 19 | 20 | return existing; 21 | } 22 | 23 | public static XElement GetOrAdd(this XElement element, string name) 24 | { 25 | var existing = element.Element(name); 26 | if (existing == null) 27 | { 28 | existing = new XElement(name); 29 | element.Add(existing); 30 | } 31 | 32 | return existing; 33 | } 34 | 35 | public static XElement GetOrAdd(this XElement element, string name, string attribute, string attributeValue) 36 | { 37 | var existing = element.Elements(name).FirstOrDefault(e => e.Attribute(attribute)?.Value == attributeValue); 38 | if (existing == null) 39 | { 40 | existing = new XElement(name, new XAttribute(attribute, attributeValue)); 41 | element.Add(existing); 42 | } 43 | 44 | return existing; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV1/AspNetCore/Inc/debugutil.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #define ASPNETCORE_DEBUG_FLAG_INFO 0x00000001 7 | #define ASPNETCORE_DEBUG_FLAG_WARNING 0x00000002 8 | #define ASPNETCORE_DEBUG_FLAG_ERROR 0x00000004 9 | 10 | extern DWORD g_dwAspNetCoreDebugFlags; 11 | 12 | static 13 | BOOL 14 | IfDebug( 15 | DWORD dwFlag 16 | ) 17 | { 18 | return ( dwFlag & g_dwAspNetCoreDebugFlags ); 19 | } 20 | 21 | static 22 | VOID 23 | DebugPrint( 24 | DWORD dwFlag, 25 | LPCSTR szString 26 | ) 27 | { 28 | STACK_STRA (strOutput, 256); 29 | HRESULT hr = S_OK; 30 | 31 | if ( IfDebug( dwFlag ) ) 32 | { 33 | hr = strOutput.SafeSnprintf( 34 | "[aspnetcore.dll] %s\r\n", 35 | szString ); 36 | 37 | if (FAILED (hr)) 38 | { 39 | goto Finished; 40 | } 41 | 42 | OutputDebugStringA( strOutput.QueryStr() ); 43 | } 44 | 45 | Finished: 46 | 47 | return; 48 | } 49 | 50 | static 51 | VOID 52 | DebugPrintf( 53 | DWORD dwFlag, 54 | LPCSTR szFormat, 55 | ... 56 | ) 57 | { 58 | STACK_STRA (strCooked,256); 59 | 60 | va_list args; 61 | HRESULT hr = S_OK; 62 | 63 | if ( IfDebug( dwFlag ) ) 64 | { 65 | va_start( args, szFormat ); 66 | 67 | hr = strCooked.SafeVsnprintf(szFormat, args ); 68 | 69 | va_end( args ); 70 | 71 | if (FAILED (hr)) 72 | { 73 | goto Finished; 74 | } 75 | 76 | DebugPrint( dwFlag, strCooked.QueryStr() ); 77 | } 78 | 79 | Finished: 80 | return; 81 | } 82 | 83 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/StringHelpers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | [[nodiscard]] 9 | bool ends_with(const std::wstring &source, const std::wstring &suffix, bool ignoreCase = false); 10 | 11 | [[nodiscard]] 12 | bool equals_ignore_case(const std::wstring& s1, const std::wstring& s2); 13 | 14 | [[nodiscard]] 15 | std::wstring to_wide_string(const std::string &source, const unsigned int codePage); 16 | 17 | template 18 | [[nodiscard]] 19 | std::wstring format(const std::wstring& format, Args ... args) 20 | { 21 | std::wstring result; 22 | if (!format.empty()) 23 | { 24 | const size_t size = swprintf(nullptr, 0, format.c_str(), args ...); // Extra char for '\0' 25 | result.resize(size); 26 | if (swprintf(result.data(), result.size() + 1, format.c_str(), args ... ) == -1) 27 | { 28 | throw std::system_error(std::error_code(errno, std::system_category())); 29 | } 30 | } 31 | return result; 32 | } 33 | 34 | template 35 | [[nodiscard]] 36 | std::string format(const std::string& format, Args ... args) 37 | { 38 | std::string result; 39 | if (!format.empty()) 40 | { 41 | const size_t size = snprintf(nullptr, 0, format.c_str(), args ...); // Extra char for '\0' 42 | result.resize(size); 43 | if (snprintf(result.data(), result.size() + 1, format.c_str(), args ... ) == -1) 44 | { 45 | throw std::system_error(std::error_code(errno, std::system_category())); 46 | } 47 | } 48 | return result; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Server.IIS/Core/WriteOnlyStream.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace Microsoft.AspNetCore.Server.IIS.Core 10 | { 11 | public abstract class WriteOnlyStream : Stream 12 | { 13 | public override bool CanRead => false; 14 | 15 | public override bool CanWrite => true; 16 | 17 | public override int ReadTimeout 18 | { 19 | get => throw new NotSupportedException(); 20 | set => throw new NotSupportedException(); 21 | } 22 | 23 | public override bool CanSeek => false; 24 | 25 | public override long Length => throw new NotSupportedException(); 26 | 27 | public override long Position 28 | { 29 | get => throw new NotSupportedException(); 30 | set => throw new NotSupportedException(); 31 | } 32 | 33 | public override int Read(byte[] buffer, int offset, int count) 34 | { 35 | throw new NotSupportedException(); 36 | } 37 | 38 | public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) 39 | { 40 | throw new NotSupportedException(); 41 | } 42 | 43 | public override long Seek(long offset, SeekOrigin origin) 44 | { 45 | throw new NotSupportedException(); 46 | } 47 | 48 | public override void SetLength(long value) 49 | { 50 | throw new NotSupportedException(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/PollingAppOfflineApplication.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | #include 6 | #include "application.h" 7 | 8 | enum PollingAppOfflineApplicationMode 9 | { 10 | StopWhenAdded, 11 | StopWhenRemoved 12 | }; 13 | 14 | class PollingAppOfflineApplication: public APPLICATION 15 | { 16 | public: 17 | PollingAppOfflineApplication(const IHttpApplication& pApplication, PollingAppOfflineApplicationMode mode) 18 | : APPLICATION(pApplication), 19 | m_ulLastCheckTime(0), 20 | m_appOfflineLocation(GetAppOfflineLocation(pApplication)), 21 | m_fAppOfflineFound(false), 22 | m_mode(mode) 23 | { 24 | InitializeSRWLock(&m_statusLock); 25 | } 26 | 27 | HRESULT 28 | TryCreateHandler( 29 | _In_ IHttpContext *pHttpContext, 30 | _Outptr_result_maybenull_ IREQUEST_HANDLER **pRequestHandler) override; 31 | 32 | void CheckAppOffline(); 33 | virtual HRESULT OnAppOfflineFound() = 0; 34 | void StopInternal(bool fServerInitiated) override { UNREFERENCED_PARAMETER(fServerInitiated); } 35 | 36 | protected: 37 | std::filesystem::path m_appOfflineLocation; 38 | static std::filesystem::path GetAppOfflineLocation(const IHttpApplication& pApplication); 39 | static bool FileExists(const std::filesystem::path& path) noexcept; 40 | private: 41 | static const int c_appOfflineRefreshIntervalMS = 200; 42 | std::string m_strAppOfflineContent; 43 | ULONGLONG m_ulLastCheckTime; 44 | bool m_fAppOfflineFound; 45 | SRWLOCK m_statusLock {}; 46 | PollingAppOfflineApplicationMode m_mode; 47 | }; 48 | -------------------------------------------------------------------------------- /test/WebSites/InProcessWebSite/InProcessWebSite.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | netcoreapp2.2 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/AspNetCore/HandlerResolver.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include "ShimOptions.h" 9 | #include "hostfxroptions.h" 10 | #include "HandleWrapper.h" 11 | #include "ApplicationFactory.h" 12 | #include "BaseOutputManager.h" 13 | 14 | class HandlerResolver 15 | { 16 | public: 17 | HandlerResolver(HMODULE hModule, const IHttpServer &pServer); 18 | HRESULT GetApplicationFactory(const IHttpApplication &pApplication, std::unique_ptr& pApplicationFactory, const ShimOptions& options); 19 | void ResetHostingModel(); 20 | 21 | private: 22 | HRESULT LoadRequestHandlerAssembly(const IHttpApplication &pApplication, const ShimOptions& pConfiguration, std::unique_ptr& pApplicationFactory); 23 | HRESULT FindNativeAssemblyFromGlobalLocation(const ShimOptions& pConfiguration, PCWSTR libraryName, std::wstring& handlerDllPath); 24 | HRESULT FindNativeAssemblyFromHostfxr(const HOSTFXR_OPTIONS& hostfxrOptions, PCWSTR libraryName, std::wstring& handlerDllPath, BaseOutputManager* outputManager); 25 | 26 | HMODULE m_hModule; 27 | const IHttpServer &m_pServer; 28 | 29 | SRWLOCK m_requestHandlerLoadLock {}; 30 | std::wstring m_loadedApplicationId; 31 | APP_HOSTING_MODEL m_loadedApplicationHostingModel; 32 | HandleWrapper m_hHostFxrDll; 33 | 34 | static const PCWSTR s_pwzAspnetcoreInProcessRequestHandlerName; 35 | static const PCWSTR s_pwzAspnetcoreOutOfProcessRequestHandlerName; 36 | static const DWORD s_initialGetNativeSearchDirectoriesBufferSize = MAX_PATH * 4; 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/fx_ver.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | // Note: This is not SemVer (esp., in comparing pre-release part, fx_ver_t does not 9 | // compare multiple dot separated identifiers individually.) ex: 1.0.0-beta.2 vs. 1.0.0-beta.11 10 | struct fx_ver_t 11 | { 12 | fx_ver_t(int major, int minor, int patch); 13 | fx_ver_t(int major, int minor, int patch, const std::wstring& pre); 14 | fx_ver_t(int major, int minor, int patch, const std::wstring& pre, const std::wstring& build); 15 | 16 | int get_major() const noexcept { return m_major; } 17 | int get_minor() const noexcept { return m_minor; } 18 | int get_patch() const noexcept { return m_patch; } 19 | 20 | void set_major(int m) noexcept { m_major = m; } 21 | void set_minor(int m) noexcept { m_minor = m; } 22 | void set_patch(int p) noexcept { m_patch = p; } 23 | 24 | bool is_prerelease() const noexcept { return !m_pre.empty(); } 25 | 26 | std::wstring as_str() const; 27 | 28 | bool operator ==(const fx_ver_t& b) const; 29 | bool operator !=(const fx_ver_t& b) const; 30 | bool operator <(const fx_ver_t& b) const; 31 | bool operator >(const fx_ver_t& b) const; 32 | bool operator <=(const fx_ver_t& b) const; 33 | bool operator >=(const fx_ver_t& b) const; 34 | 35 | static bool parse(const std::wstring& ver, fx_ver_t* fx_ver, bool parse_only_production = false); 36 | 37 | private: 38 | int m_major; 39 | int m_minor; 40 | int m_patch; 41 | std::wstring m_pre; 42 | std::wstring m_build; 43 | 44 | static int compare(const fx_ver_t&a, const fx_ver_t& b); 45 | }; 46 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Utilities/IISCompressionSiteFixture.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Net.Http; 7 | using System.Threading; 8 | using Microsoft.AspNetCore.Server.IntegrationTesting; 9 | using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; 10 | using Microsoft.Extensions.Logging; 11 | using Microsoft.Extensions.Logging.Testing; 12 | 13 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 14 | { 15 | public class IISCompressionSiteFixture : IISTestSiteFixture 16 | { 17 | public IISCompressionSiteFixture() : base(Configure) 18 | { 19 | } 20 | 21 | private static void Configure(IISDeploymentParameters deploymentParameters) 22 | { 23 | // Enable dynamic compression 24 | deploymentParameters.ServerConfigActionList.Add( 25 | (element, _) => { 26 | var webServerElement = element 27 | .RequiredElement("system.webServer"); 28 | 29 | webServerElement 30 | .GetOrAdd("urlCompression") 31 | .SetAttributeValue("doDynamicCompression", "true"); 32 | 33 | webServerElement 34 | .GetOrAdd("httpCompression") 35 | .GetOrAdd("dynamicTypes") 36 | .GetOrAdd("add", "mimeType", "text/*") 37 | .SetAttributeValue("enabled", "true"); 38 | 39 | }); 40 | 41 | deploymentParameters.EnableModule("DynamicCompressionModule", "%IIS_BIN%\\compdyn.dll"); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/OutOfProcessRequestHandler/HtmlResponses.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | 21 | #ifdef APSTUDIO_INVOKED 22 | ///////////////////////////////////////////////////////////////////////////// 23 | // 24 | // TEXTINCLUDE 25 | // 26 | 27 | 1 TEXTINCLUDE 28 | BEGIN 29 | "resource.h\0" 30 | END 31 | 32 | 2 TEXTINCLUDE 33 | BEGIN 34 | "#include ""winres.h""\r\n" 35 | "\0" 36 | END 37 | 38 | 3 TEXTINCLUDE 39 | BEGIN 40 | "\r\n" 41 | "\0" 42 | END 43 | 44 | #endif // APSTUDIO_INVOKED 45 | 46 | 47 | ///////////////////////////////////////////////////////////////////////////// 48 | // 49 | // HTML 50 | // 51 | 52 | OUT_OF_PROCESS_RH_STATIC_HTML HTML "OutOfProcessRhStaticHtml.htm" 53 | 54 | #endif // English (United States) resources 55 | ///////////////////////////////////////////////////////////////////////////// 56 | 57 | 58 | 59 | #ifndef APSTUDIO_INVOKED 60 | ///////////////////////////////////////////////////////////////////////////// 61 | // 62 | // Generated from the TEXTINCLUDE 3 resource. 63 | // 64 | 65 | 66 | ///////////////////////////////////////////////////////////////////////////// 67 | #endif // not APSTUDIO_INVOKED 68 | 69 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/Inprocess/EventLogTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; 6 | using Microsoft.AspNetCore.Testing.xunit; 7 | using Xunit; 8 | 9 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 10 | { 11 | [Collection(PublishedSitesCollection.Name)] 12 | public class EventLogTests : IISFunctionalTestBase 13 | { 14 | private readonly PublishedSitesFixture _fixture; 15 | 16 | public EventLogTests(PublishedSitesFixture fixture) 17 | { 18 | _fixture = fixture; 19 | } 20 | 21 | [ConditionalFact] 22 | public async Task CheckStartupEventLogMessage() 23 | { 24 | var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); 25 | 26 | var deploymentResult = await DeployAsync(deploymentParameters); 27 | await deploymentResult.AssertStarts(); 28 | 29 | StopServer(); 30 | 31 | EventLogHelpers.VerifyEventLogEvent(deploymentResult, "Application '.+' started the coreclr in-process successfully."); 32 | } 33 | 34 | [ConditionalFact] 35 | public async Task CheckShutdownEventLogMessage() 36 | { 37 | var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true); 38 | var deploymentResult = await DeployAsync(deploymentParameters); 39 | await deploymentResult.AssertStarts(); 40 | 41 | StopServer(); 42 | 43 | EventLogHelpers.VerifyEventLogEvent(deploymentResult, "Application '.+' has shutdown."); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/CommonLib/LoggingHelpers.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include "stdafx.h" 5 | #include "LoggingHelpers.h" 6 | #include "FileOutputManager.h" 7 | #include "PipeOutputManager.h" 8 | #include "NullOutputManager.h" 9 | #include "debugutil.h" 10 | #include 11 | #include 12 | #include "ntassert.h" 13 | #include "exceptions.h" 14 | #include "EventLog.h" 15 | #include "BaseOutputManager.h" 16 | 17 | HRESULT 18 | LoggingHelpers::CreateLoggingProvider( 19 | bool fIsLoggingEnabled, 20 | bool fEnableNativeLogging, 21 | PCWSTR pwzStdOutFileName, 22 | PCWSTR pwzApplicationPath, 23 | std::unique_ptr& outputManager 24 | ) 25 | { 26 | HRESULT hr = S_OK; 27 | 28 | DBG_ASSERT(outputManager != NULL); 29 | 30 | try 31 | { 32 | // Check if there is an existing active console window before redirecting 33 | // Window == IISExpress with active console window, don't redirect to a pipe 34 | // if true. 35 | CONSOLE_SCREEN_BUFFER_INFO dummy; 36 | 37 | if (fIsLoggingEnabled) 38 | { 39 | auto manager = std::make_unique(pwzStdOutFileName, pwzApplicationPath, fEnableNativeLogging); 40 | outputManager = std::move(manager); 41 | } 42 | else if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &dummy)) 43 | { 44 | outputManager = std::make_unique(fEnableNativeLogging); 45 | } 46 | else 47 | { 48 | outputManager = std::make_unique(); 49 | } 50 | } 51 | catch (std::bad_alloc&) 52 | { 53 | hr = E_OUTOFMEMORY; 54 | } 55 | 56 | return hr; 57 | } 58 | -------------------------------------------------------------------------------- /test/Common.FunctionalTests/CommonStartupTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Net; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; 7 | using Microsoft.AspNetCore.Server.IntegrationTesting; 8 | using Microsoft.AspNetCore.Testing.xunit; 9 | using Xunit; 10 | 11 | namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests 12 | { 13 | [Collection(PublishedSitesCollection.Name)] 14 | public class CommonStartupTests : IISFunctionalTestBase 15 | { 16 | private readonly PublishedSitesFixture _fixture; 17 | 18 | public CommonStartupTests(PublishedSitesFixture fixture) 19 | { 20 | _fixture = fixture; 21 | } 22 | 23 | public static TestMatrix TestVariants 24 | => TestMatrix.ForServers(DeployerSelector.ServerType) 25 | .WithTfms(Tfm.NetCoreApp22) 26 | .WithAllApplicationTypes() 27 | .WithAllAncmVersions() 28 | .WithAllHostingModels(); 29 | 30 | [ConditionalTheory] 31 | [MemberData(nameof(TestVariants))] 32 | public async Task StartupStress(TestVariant variant) 33 | { 34 | var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant, publish: true); 35 | 36 | var deploymentResult = await DeployAsync(deploymentParameters); 37 | 38 | await Helpers.StressLoad(deploymentResult.HttpClient, "/HelloWorld", response => { 39 | Assert.Equal(HttpStatusCode.OK, response.StatusCode); 40 | Assert.Equal("Hello World", response.Content.ReadAsStringAsync().GetAwaiter().GetResult()); 41 | }); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/RequestHandlerLib/filewatcher.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include "iapplication.h" 10 | #include "HandleWrapper.h" 11 | 12 | #define FILE_WATCHER_SHUTDOWN_KEY (ULONG_PTR)(-1) 13 | #define FILE_WATCHER_ENTRY_BUFFER_SIZE 4096 14 | #define FILE_NOTIFY_VALID_MASK 0x00000fff 15 | 16 | class AppOfflineTrackingApplication; 17 | 18 | class FILE_WATCHER{ 19 | public: 20 | 21 | FILE_WATCHER(); 22 | 23 | ~FILE_WATCHER(); 24 | 25 | HRESULT Create( 26 | _In_ PCWSTR pszDirectoryToMonitor, 27 | _In_ PCWSTR pszFileNameToMonitor, 28 | _In_ AppOfflineTrackingApplication *pApplication 29 | ); 30 | 31 | static 32 | DWORD 33 | WINAPI ChangeNotificationThread(LPVOID); 34 | 35 | static 36 | DWORD 37 | WINAPI RunNotificationCallback(LPVOID); 38 | 39 | HRESULT HandleChangeCompletion(DWORD cbCompletion); 40 | 41 | HRESULT Monitor(); 42 | void StopMonitor(); 43 | 44 | private: 45 | HandleWrapper m_hCompletionPort; 46 | HandleWrapper m_hChangeNotificationThread; 47 | HandleWrapper _hDirectory; 48 | volatile BOOL m_fThreadExit; 49 | 50 | BUFFER _buffDirectoryChanges; 51 | STRU _strFileName; 52 | STRU _strDirectoryName; 53 | STRU _strFullName; 54 | LONG _lStopMonitorCalled {}; 55 | OVERLAPPED _overlapped; 56 | std::unique_ptr _pApplication; 57 | }; 58 | -------------------------------------------------------------------------------- /src/AspNetCoreModuleV2/InProcessRequestHandler/InProcessApplicationBase.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. See License.txt in the project root for license information. 3 | 4 | #include "InProcessApplicationBase.h" 5 | 6 | InProcessApplicationBase::InProcessApplicationBase( 7 | IHttpServer& pHttpServer, 8 | IHttpApplication& pHttpApplication) 9 | : AppOfflineTrackingApplication(pHttpApplication), 10 | m_fRecycleCalled(FALSE), 11 | m_pHttpServer(pHttpServer) 12 | { 13 | } 14 | 15 | VOID 16 | InProcessApplicationBase::StopInternal(bool fServerInitiated) 17 | { 18 | AppOfflineTrackingApplication::StopInternal(fServerInitiated); 19 | 20 | // Stop was initiated by server no need to do anything, server would stop on it's own 21 | if (fServerInitiated) 22 | { 23 | return; 24 | } 25 | 26 | if (!m_pHttpServer.IsCommandLineLaunch()) 27 | { 28 | // IIS scenario. 29 | // We don't actually handle any shutdown logic here. 30 | // Instead, we notify IIS that the process needs to be recycled, which will call 31 | // ApplicationManager->Shutdown(). This will call shutdown on the application. 32 | m_pHttpServer.RecycleProcess(L"AspNetCore InProcess Recycle Process on Demand"); 33 | } 34 | else 35 | { 36 | // Send WM_QUIT to the main window to initiate graceful shutdown 37 | EnumWindows([](HWND hwnd, LPARAM) -> BOOL 38 | { 39 | DWORD processId; 40 | 41 | if (GetWindowThreadProcessId(hwnd, &processId) && 42 | processId == GetCurrentProcessId() && 43 | GetConsoleWindow() != hwnd) 44 | { 45 | PostMessage(hwnd, WM_QUIT, 0, 0); 46 | return false; 47 | } 48 | 49 | return true; 50 | }, 0); 51 | } 52 | } 53 | 54 | --------------------------------------------------------------------------------