Add Hostable Web Core based inprocess test server (#853)

This commit is contained in:
Pavel Krymets 2018-05-24 08:11:40 -07:00 committed by GitHub
parent 23cb0c90b2
commit 1e143c71c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 1329 additions and 770 deletions

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<!-- Using shorter assembly name instead of Microsoft.AspNetCore.Server.Kestrel.Performance because https://github.com/dotnet/BenchmarkDotNet/issues/498 --> <!-- Using shorter assembly name instead of Microsoft.AspNetCore.Server.Kestrel.Performance because https://github.com/dotnet/BenchmarkDotNet/issues/498 -->
@ -15,13 +15,21 @@
<Content Include="..\..\test\IISIntegration.FunctionalTests\AppHostConfig\*.config" CopyToOutputDirectory="PreserveNewest" /> <Content Include="..\..\test\IISIntegration.FunctionalTests\AppHostConfig\*.config" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\InProcessRequestHandler\bin\$(Configuration)\x64\aspnetcorev2_inprocess.dll" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\InProcessRequestHandler\bin\$(Configuration)\x64\aspnetcorev2_inprocess.pdb" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\AspNetCore\bin\$(Configuration)\x64\aspnetcorev2.dll" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\AspNetCore\bin\$(Configuration)\x64\aspnetcorev2.pdb" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" /> <ProjectReference Include="..\..\src\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" />
<ProjectReference Include="..\..\test\IISIntegration.FunctionalTests\IISIntegration.FunctionalTests.csproj" />
<ProjectReference Include="..\..\test\WebSites\**\*.csproj"> <ProjectReference Include="..\..\test\WebSites\**\*.csproj">
<ReferenceOutputAssembly>False</ReferenceOutputAssembly> <ReferenceOutputAssembly>False</ReferenceOutputAssembly>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetPackageVersion)" /> <PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.BenchmarkRunner.Sources" PrivateAssets="All" Version="$(MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.BenchmarkRunner.Sources" PrivateAssets="All" Version="$(MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion)" />

View File

@ -0,0 +1,73 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using IISIntegration.FunctionalTests.Utilities;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.IIS.Performance
{
[AspNetCoreBenchmark]
public class PlaintextBenchmark
{
private TestServer _server;
private HttpClient _client;
[GlobalSetup]
public void Setup()
{
_server = TestServer.Create(builder => builder.UseMiddleware<PlaintextMiddleware>(), new LoggerFactory()).GetAwaiter().GetResult();
// Recreate client, TestServer.Client has additional logging that can hurt performance
_client = new HttpClient()
{
BaseAddress = _server.HttpClient.BaseAddress
};
}
[Benchmark]
public async Task Plaintext()
{
await _client.GetAsync("/plaintext");
}
// Copied from https://github.com/aspnet/benchmarks/blob/dev/src/Benchmarks/Middleware/PlaintextMiddleware.cs
public class PlaintextMiddleware
{
private static readonly PathString _path = new PathString("/plaintext");
private static readonly byte[] _helloWorldPayload = Encoding.UTF8.GetBytes("Hello, World!");
private readonly RequestDelegate _next;
public PlaintextMiddleware(RequestDelegate next)
{
_next = next;
}
public Task Invoke(HttpContext httpContext)
{
if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal))
{
return WriteResponse(httpContext.Response);
}
return _next(httpContext);
}
public static Task WriteResponse(HttpResponse response)
{
var payloadLength = _helloWorldPayload.Length;
response.StatusCode = 200;
response.ContentType = "text/plain";
response.ContentLength = payloadLength;
return response.Body.WriteAsync(_helloWorldPayload, 0, payloadLength);
}
}
}
}

View File

@ -5,7 +5,6 @@ using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;

View File

@ -1,262 +1,262 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\Build\Build.Settings" /> <Import Project="..\..\..\Build\Build.Settings" />
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64"> <ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>x64</Platform> <Platform>x64</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32"> <ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|x64"> <ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>x64</Platform> <Platform>x64</Platform>
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{EC82302F-D2F0-4727-99D1-EABC0DD9DC3B}</ProjectGuid> <ProjectGuid>{EC82302F-D2F0-4727-99D1-EABC0DD9DC3B}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>AspNetCoreModule</RootNamespace> <RootNamespace>AspNetCoreModule</RootNamespace>
<ProjectName>AspNetCore</ProjectName> <ProjectName>AspNetCore</ProjectName>
<TargetName>aspnetcorev2</TargetName> <TargetName>aspnetcorev2</TargetName>
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup> <PropertyGroup>
<OutDir>$(MSBuildProjectDirectory)\bin\$(Configuration)\$(Platform)\</OutDir> <OutDir>$(MSBuildProjectDirectory)\bin\$(Configuration)\$(Platform)\</OutDir>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;ASPNETCOREMODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;ASPNETCOREMODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>precomp.hxx</PrecompiledHeaderFile> <PrecompiledHeaderFile>precomp.hxx</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile>
<AdditionalIncludeDirectories>..\IISLib;inc;..\CommonLib</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\IISLib;inc;..\CommonLib</AdditionalIncludeDirectories>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<PreprocessKeepComments>false</PreprocessKeepComments> <PreprocessKeepComments>false</PreprocessKeepComments>
<ExceptionHandling>SyncCThrow</ExceptionHandling> <ExceptionHandling>SyncCThrow</ExceptionHandling>
<StructMemberAlignment>8Bytes</StructMemberAlignment> <StructMemberAlignment>8Bytes</StructMemberAlignment>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<RuntimeTypeInfo>false</RuntimeTypeInfo> <RuntimeTypeInfo>false</RuntimeTypeInfo>
<OmitDefaultLibName>true</OmitDefaultLibName> <OmitDefaultLibName>true</OmitDefaultLibName>
<CompileAs>CompileAsCpp</CompileAs> <CompileAs>CompileAsCpp</CompileAs>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>kernel32.lib;user32.lib;advapi32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ahadmin.lib;rpcrt4.lib;winhttp.lib;pdh.lib;ws2_32.lib;wbemuuid.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>kernel32.lib;user32.lib;advapi32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ahadmin.lib;rpcrt4.lib;winhttp.lib;pdh.lib;ws2_32.lib;wbemuuid.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile> <ModuleDefinitionFile>Source.def</ModuleDefinitionFile>
</Link> </Link>
<ResourceCompile> <ResourceCompile>
<AdditionalIncludeDirectories>..\Commonlib</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\Commonlib</AdditionalIncludeDirectories>
</ResourceCompile> </ResourceCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile> <ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;ASPNETCOREMODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;ASPNETCOREMODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>precomp.hxx</PrecompiledHeaderFile> <PrecompiledHeaderFile>precomp.hxx</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile> <PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile>
<AdditionalIncludeDirectories>..\IISLib;inc;..\CommonLib</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\IISLib;inc;..\CommonLib</AdditionalIncludeDirectories>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<PreprocessKeepComments>false</PreprocessKeepComments> <PreprocessKeepComments>false</PreprocessKeepComments>
<ExceptionHandling>SyncCThrow</ExceptionHandling> <ExceptionHandling>SyncCThrow</ExceptionHandling>
<StructMemberAlignment>8Bytes</StructMemberAlignment> <StructMemberAlignment>8Bytes</StructMemberAlignment>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<RuntimeTypeInfo>false</RuntimeTypeInfo> <RuntimeTypeInfo>false</RuntimeTypeInfo>
<OmitDefaultLibName>true</OmitDefaultLibName> <OmitDefaultLibName>true</OmitDefaultLibName>
<CompileAs>CompileAsCpp</CompileAs> <CompileAs>CompileAsCpp</CompileAs>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>kernel32.lib;user32.lib;advapi32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ahadmin.lib;rpcrt4.lib;winhttp.lib;pdh.lib;ws2_32.lib;wbemuuid.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>kernel32.lib;user32.lib;advapi32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ahadmin.lib;rpcrt4.lib;winhttp.lib;pdh.lib;ws2_32.lib;wbemuuid.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile> <ModuleDefinitionFile>Source.def</ModuleDefinitionFile>
</Link> </Link>
<ResourceCompile> <ResourceCompile>
<AdditionalIncludeDirectories>..\Commonlib</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\Commonlib</AdditionalIncludeDirectories>
</ResourceCompile> </ResourceCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ASPNETCOREMODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ASPNETCOREMODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\IISLib;inc;..\CommonLib</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\IISLib;inc;..\CommonLib</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>precomp.hxx</PrecompiledHeaderFile> <PrecompiledHeaderFile>precomp.hxx</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<PreprocessKeepComments>false</PreprocessKeepComments> <PreprocessKeepComments>false</PreprocessKeepComments>
<ExceptionHandling>SyncCThrow</ExceptionHandling> <ExceptionHandling>SyncCThrow</ExceptionHandling>
<StructMemberAlignment>8Bytes</StructMemberAlignment> <StructMemberAlignment>8Bytes</StructMemberAlignment>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<RuntimeTypeInfo>false</RuntimeTypeInfo> <RuntimeTypeInfo>false</RuntimeTypeInfo>
<OmitDefaultLibName>true</OmitDefaultLibName> <OmitDefaultLibName>true</OmitDefaultLibName>
<CompileAs>CompileAsCpp</CompileAs> <CompileAs>CompileAsCpp</CompileAs>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile> <ModuleDefinitionFile>Source.def</ModuleDefinitionFile>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;ahadmin.lib;winhttp.lib;odbc32.lib;ws2_32.lib;odbccp32.lib;wbemuuid.lib;iphlpapi.lib;pdh.lib;rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;ahadmin.lib;winhttp.lib;odbc32.lib;ws2_32.lib;odbccp32.lib;wbemuuid.lib;iphlpapi.lib;pdh.lib;rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
<ResourceCompile> <ResourceCompile>
<AdditionalIncludeDirectories>..\Commonlib</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\Commonlib</AdditionalIncludeDirectories>
</ResourceCompile> </ResourceCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile> <ClCompile>
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ASPNETCOREMODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ASPNETCOREMODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>precomp.hxx</PrecompiledHeaderFile> <PrecompiledHeaderFile>precomp.hxx</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\IISLib;inc;..\CommonLib</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\IISLib;inc;..\CommonLib</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<PreprocessKeepComments>false</PreprocessKeepComments> <PreprocessKeepComments>false</PreprocessKeepComments>
<ExceptionHandling>SyncCThrow</ExceptionHandling> <ExceptionHandling>SyncCThrow</ExceptionHandling>
<StructMemberAlignment>8Bytes</StructMemberAlignment> <StructMemberAlignment>8Bytes</StructMemberAlignment>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<RuntimeTypeInfo>false</RuntimeTypeInfo> <RuntimeTypeInfo>false</RuntimeTypeInfo>
<OmitDefaultLibName>true</OmitDefaultLibName> <OmitDefaultLibName>true</OmitDefaultLibName>
<CompileAs>CompileAsCpp</CompileAs> <CompileAs>CompileAsCpp</CompileAs>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile> <ModuleDefinitionFile>Source.def</ModuleDefinitionFile>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;ahadmin.lib;rpcrt4.lib;winhttp.lib;pdh.lib;ws2_32.lib;wbemuuid.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;ahadmin.lib;rpcrt4.lib;winhttp.lib;pdh.lib;ws2_32.lib;wbemuuid.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
<ResourceCompile> <ResourceCompile>
<AdditionalIncludeDirectories>..\Commonlib</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\Commonlib</AdditionalIncludeDirectories>
</ResourceCompile> </ResourceCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Inc\applicationinfo.h" /> <ClInclude Include="Inc\applicationinfo.h" />
<ClInclude Include="Inc\appoffline.h" /> <ClInclude Include="Inc\appoffline.h" />
<ClInclude Include="Inc\aspnetcore_shim_config.h" /> <ClInclude Include="Inc\aspnetcore_shim_config.h" />
<ClInclude Include="inc\globalmodule.h" /> <ClInclude Include="inc\globalmodule.h" />
<ClInclude Include="Inc\applicationmanager.h" /> <ClInclude Include="Inc\applicationmanager.h" />
<ClInclude Include="Inc\filewatcher.h" /> <ClInclude Include="Inc\filewatcher.h" />
<ClInclude Include="Inc\proxymodule.h" /> <ClInclude Include="Inc\proxymodule.h" />
<ClInclude Include="Src\precomp.hxx" /> <ClInclude Include="Src\precomp.hxx" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Src\applicationinfo.cpp" /> <ClCompile Include="Src\applicationinfo.cpp" />
<ClCompile Include="Src\applicationmanager.cxx" /> <ClCompile Include="Src\applicationmanager.cxx" />
<ClCompile Include="src\aspnetcore_shim_config.cpp" /> <ClCompile Include="src\aspnetcore_shim_config.cpp" />
<ClCompile Include="Src\dllmain.cpp" /> <ClCompile Include="Src\dllmain.cpp" />
<ClCompile Include="Src\filewatcher.cxx" /> <ClCompile Include="Src\filewatcher.cxx" />
<ClCompile Include="src\globalmodule.cpp" /> <ClCompile Include="src\globalmodule.cpp" />
<ClCompile Include="Src\proxymodule.cxx" /> <ClCompile Include="Src\proxymodule.cxx" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\CommonLib\CommonLib.vcxproj"> <ProjectReference Include="..\CommonLib\CommonLib.vcxproj">
<Project>{55494e58-e061-4c4c-a0a8-837008e72f85}</Project> <Project>{55494e58-e061-4c4c-a0a8-837008e72f85}</Project>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\IISLib\IISLib.vcxproj"> <ProjectReference Include="..\IISLib\IISLib.vcxproj">
<Project>{09d9d1d6-2951-4e14-bc35-76a23cf9391a}</Project> <Project>{09d9d1d6-2951-4e14-bc35-76a23cf9391a}</Project>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="ancm.mof" /> <None Include="ancm.mof" />
<None Include="Source.def" /> <None Include="Source.def" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="aspnetcoremodule.rc" /> <ResourceCompile Include="aspnetcoremodule.rc" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="aspnetcore_schema_v2.xml"> <Content Include="aspnetcore_schema_v2.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="ancm.mof"> <Content Include="ancm.mof">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Xml Include="aspnetcore_schema_v2.xml" /> <Xml Include="aspnetcore_schema_v2.xml" />
</ItemGroup> </ItemGroup>
<Import Project="..\..\..\build\native.targets" /> <Import Project="..\..\..\build\native.targets" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@ -2,6 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.
#pragma once #pragma once
#define API_BUFFER_TOO_SMALL 0x80008098 #define API_BUFFER_TOO_SMALL 0x80008098
extern BOOL g_fRecycleProcessCalled; extern BOOL g_fRecycleProcessCalled;
@ -147,14 +148,13 @@ public:
HRESULT HRESULT
EnsureApplicationCreated( EnsureApplicationCreated(
IHttpContext *pHttpContext, IHttpContext *pHttpContext
STRU* exeLocation
); );
private: private:
HRESULT FindRequestHandlerAssembly(); HRESULT FindRequestHandlerAssembly(STRU& location);
HRESULT FindNativeAssemblyFromGlobalLocation(STRU* struFilename); HRESULT FindNativeAssemblyFromGlobalLocation(PCWSTR libraryName, STRU* location);
HRESULT FindNativeAssemblyFromHostfxr(STRU* struFilename); HRESULT FindNativeAssemblyFromHostfxr(HOSTFXR_OPTIONS* hostfxrOptions, PCWSTR libraryName, STRU* location);
static VOID DoRecycleApplication(LPVOID lpParam); static VOID DoRecycleApplication(LPVOID lpParam);

View File

@ -26,8 +26,6 @@ public:
_In_ IHttpServer *pHttpServer, _In_ IHttpServer *pHttpServer,
_In_ HTTP_MODULE_ID pModuleId, _In_ HTTP_MODULE_ID pModuleId,
_In_ IHttpApplication *pHttpApplication, _In_ IHttpApplication *pHttpApplication,
_In_ HANDLE hEventLog,
_Out_ STRU *pcwzExePath,
_Out_ ASPNETCORE_SHIM_CONFIG **ppAspNetCoreConfig _Out_ ASPNETCORE_SHIM_CONFIG **ppAspNetCoreConfig
); );
@ -72,24 +70,6 @@ public:
return &m_struApplication; return &m_struApplication;
} }
CONST
PCWSTR*
QueryHostFxrArguments(
VOID
)
{
return m_ppStrArguments;
}
CONST
DWORD
QueryHostFxrArgCount(
VOID
)
{
return m_dwArgc;
}
STRU* STRU*
QueryConfigPath( QueryConfigPath(
VOID VOID
@ -114,14 +94,6 @@ public:
return &m_struArguments; return &m_struArguments;
} }
HRESULT
SetHostFxrFullPath(
PCWSTR pStrHostFxrFullPath
)
{
return m_struHostFxrLocation.Copy(pStrHostFxrFullPath);
}
APP_HOSTING_MODEL APP_HOSTING_MODEL
QueryHostingModel( QueryHostingModel(
VOID VOID
@ -130,35 +102,10 @@ public:
return m_hostingModel; return m_hostingModel;
} }
CONST
PCWSTR
QueryHostFxrFullPath(
VOID
)
{
return m_struHostFxrLocation.QueryStr();
}
VOID
SetHostFxrArguments(
DWORD dwArgc,
PWSTR* ppStrArguments
)
{
if (m_ppStrArguments != NULL)
{
delete[] m_ppStrArguments;
}
m_dwArgc = dwArgc;
m_ppStrArguments = ppStrArguments;
}
private: private:
ASPNETCORE_SHIM_CONFIG() : ASPNETCORE_SHIM_CONFIG() :
m_cRefs(1), m_cRefs(1),
m_hostingModel(HOSTING_UNKNOWN), m_hostingModel(HOSTING_UNKNOWN)
m_ppStrArguments(NULL)
{ {
} }
@ -170,7 +117,5 @@ private:
STRU m_struConfigPath; STRU m_struConfigPath;
APP_HOSTING_MODEL m_hostingModel; APP_HOSTING_MODEL m_hostingModel;
STRU m_struHostFxrLocation; STRU m_struHostFxrLocation;
PWSTR* m_ppStrArguments;
DWORD m_dwArgc;
}; };

View File

@ -106,22 +106,16 @@ APPLICATION_INFO::UpdateAppOfflineFileHandle()
ReferenceApplicationInfo(); ReferenceApplicationInfo();
if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(strFilePath.QueryStr()) && if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(strFilePath.QueryStr()))
GetLastError() == ERROR_FILE_NOT_FOUND)
{ {
// Check if app offline was originally present. // Check if app offline was originally present.
// if it was, log that app_offline has been dropped. // if it was, log that app_offline has been dropped.
if (m_fAppOfflineFound) if (m_fAppOfflineFound)
{ {
STACK_STRU(strEventMsg, 256); UTILITY::LogEvent(g_hEventLog,
if (SUCCEEDED(strEventMsg.SafeSnwprintf( EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED_MSG))) ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED,
{ ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED_MSG);
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_REMOVED,
strEventMsg.QueryStr());
}
} }
m_fAppOfflineFound = FALSE; m_fAppOfflineFound = FALSE;
@ -178,13 +172,13 @@ APPLICATION_INFO::UpdateAppOfflineFileHandle()
HRESULT HRESULT
APPLICATION_INFO::EnsureApplicationCreated( APPLICATION_INFO::EnsureApplicationCreated(
IHttpContext *pHttpContext, IHttpContext *pHttpContext
STRU* struExeLocation
) )
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
BOOL fLocked = FALSE; BOOL fLocked = FALSE;
IAPPLICATION *pApplication = NULL; IAPPLICATION *pApplication = NULL;
STRU struExeLocation;
STACK_STRU(struFileName, 300); // >MAX_PATH STACK_STRU(struFileName, 300); // >MAX_PATH
STRU struHostFxrDllLocation; STRU struHostFxrDllLocation;
@ -213,7 +207,7 @@ APPLICATION_INFO::EnsureApplicationCreated(
// FindRequestHandlerAssembly obtains a global lock, but after releasing the lock, // FindRequestHandlerAssembly obtains a global lock, but after releasing the lock,
// there is a period where we could call // there is a period where we could call
hr = FindRequestHandlerAssembly(); hr = FindRequestHandlerAssembly(struExeLocation);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto Finished; goto Finished;
@ -225,13 +219,14 @@ APPLICATION_INFO::EnsureApplicationCreated(
goto Finished; goto Finished;
} }
hr = m_pfnAspNetCoreCreateApplication(m_pServer, pHttpContext, struExeLocation->QueryStr(), &pApplication); hr = m_pfnAspNetCoreCreateApplication(m_pServer, pHttpContext, struExeLocation.QueryStr(), &pApplication);
m_pApplication = pApplication; m_pApplication = pApplication;
} }
} }
Finished: Finished:
if (fLocked) if (fLocked)
{ {
ReleaseSRWLockExclusive(&m_srwLock); ReleaseSRWLockExclusive(&m_srwLock);
@ -240,10 +235,11 @@ Finished:
} }
HRESULT HRESULT
APPLICATION_INFO::FindRequestHandlerAssembly() APPLICATION_INFO::FindRequestHandlerAssembly(STRU& location)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
BOOL fLocked = FALSE; BOOL fLocked = FALSE;
PCWSTR pstrHandlerDllName;
STACK_STRU(struFileName, 256); STACK_STRU(struFileName, 256);
if (g_fAspnetcoreRHLoadedError) if (g_fAspnetcoreRHLoadedError)
@ -267,46 +263,67 @@ APPLICATION_INFO::FindRequestHandlerAssembly()
if (m_pConfiguration->QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS) if (m_pConfiguration->QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS)
{ {
if (FAILED(hr = FindNativeAssemblyFromHostfxr(&struFileName))) pstrHandlerDllName = g_pwzAspnetcoreInProcessRequestHandlerName;
{
STACK_STRU(strEventMsg, 256);
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_INPROCESS_RH_MISSING_MSG)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_INPROCESS_RH_MISSING,
strEventMsg.QueryStr());
}
goto Finished;
}
} }
else else
{ {
if (FAILED(hr = FindNativeAssemblyFromGlobalLocation(&struFileName))) pstrHandlerDllName = g_pwzAspnetcoreOutOfProcessRequestHandlerName;
}
// Try to see if RH is already loaded
g_hAspnetCoreRH = GetModuleHandle(pstrHandlerDllName);
if (g_hAspnetCoreRH == NULL)
{
if (m_pConfiguration->QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS)
{ {
STACK_STRU(strEventMsg, 256); std:: unique_ptr<HOSTFXR_OPTIONS> options;
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING_MSG))) if (FAILED(hr = HOSTFXR_OPTIONS::Create(
NULL,
m_pConfiguration->QueryProcessPath()->QueryStr(),
m_pConfiguration->QueryApplicationPhysicalPath()->QueryStr(),
m_pConfiguration->QueryArguments()->QueryStr(),
g_hEventLog,
options)))
{
goto Finished;
}
location.Copy(options->GetExeLocation());
if (FAILED(hr = FindNativeAssemblyFromHostfxr(options.get(), pstrHandlerDllName, &struFileName)))
{
UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_INPROCESS_RH_MISSING,
ASPNETCORE_EVENT_INPROCESS_RH_MISSING_MSG);
goto Finished;
}
}
else
{
if (FAILED(hr = FindNativeAssemblyFromGlobalLocation(pstrHandlerDllName, &struFileName)))
{ {
UTILITY::LogEvent(g_hEventLog, UTILITY::LogEvent(g_hEventLog,
EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING, ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING,
strEventMsg.QueryStr()); ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING_MSG);
}
goto Finished;
}
}
g_hAspnetCoreRH = LoadLibraryW(struFileName.QueryStr());
if (g_hAspnetCoreRH == NULL)
{
hr = HRESULT_FROM_WIN32(GetLastError());
goto Finished; goto Finished;
} }
} }
g_hAspnetCoreRH = LoadLibraryW(struFileName.QueryStr());
if (g_hAspnetCoreRH == NULL)
{
hr = HRESULT_FROM_WIN32(GetLastError());
goto Finished;
}
g_pfnAspNetCoreCreateApplication = (PFN_ASPNETCORE_CREATE_APPLICATION) g_pfnAspNetCoreCreateApplication = (PFN_ASPNETCORE_CREATE_APPLICATION)
GetProcAddress(g_hAspnetCoreRH, "CreateApplication"); GetProcAddress(g_hAspnetCoreRH, "CreateApplication");
if (g_pfnAspNetCoreCreateApplication == NULL) if (g_pfnAspNetCoreCreateApplication == NULL)
@ -338,7 +355,9 @@ Finished:
} }
HRESULT HRESULT
APPLICATION_INFO::FindNativeAssemblyFromGlobalLocation(STRU* struFilename) APPLICATION_INFO::FindNativeAssemblyFromGlobalLocation(
PCWSTR libraryName,
STRU* struFilename)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
DWORD dwSize = MAX_PATH; DWORD dwSize = MAX_PATH;
@ -385,7 +404,7 @@ APPLICATION_INFO::FindNativeAssemblyFromGlobalLocation(STRU* struFilename)
if (FAILED(hr = struFilename->SyncWithBuffer()) || if (FAILED(hr = struFilename->SyncWithBuffer()) ||
FAILED(hr = struFilename->Append(L"\\")) || FAILED(hr = struFilename->Append(L"\\")) ||
FAILED(hr = struFilename->Append(g_pwzAspnetcoreOutOfProcessRequestHandlerName))) FAILED(hr = struFilename->Append(libraryName)))
{ {
goto Finished; goto Finished;
} }
@ -401,6 +420,8 @@ Finished:
// //
HRESULT HRESULT
APPLICATION_INFO::FindNativeAssemblyFromHostfxr( APPLICATION_INFO::FindNativeAssemblyFromHostfxr(
HOSTFXR_OPTIONS* hostfxrOptions,
PCWSTR libraryName,
STRU* struFilename STRU* struFilename
) )
{ {
@ -418,7 +439,7 @@ APPLICATION_INFO::FindNativeAssemblyFromHostfxr(
DBG_ASSERT(struFileName != NULL); DBG_ASSERT(struFileName != NULL);
hmHostFxrDll = LoadLibraryW(m_pConfiguration->QueryHostFxrFullPath()); hmHostFxrDll = LoadLibraryW(hostfxrOptions->GetHostFxrLocation());
if (hmHostFxrDll == NULL) if (hmHostFxrDll == NULL)
{ {
@ -446,8 +467,8 @@ APPLICATION_INFO::FindNativeAssemblyFromHostfxr(
while (TRUE) while (TRUE)
{ {
intHostFxrExitCode = pFnHostFxrSearchDirectories( intHostFxrExitCode = pFnHostFxrSearchDirectories(
m_pConfiguration->QueryHostFxrArgCount(), hostfxrOptions->GetArgc(),
m_pConfiguration->QueryHostFxrArguments(), hostfxrOptions->GetArgv(),
struNativeSearchPaths.QueryStr(), struNativeSearchPaths.QueryStr(),
dwBufferSize, dwBufferSize,
&dwRequiredBufferSize &dwRequiredBufferSize
@ -498,7 +519,7 @@ APPLICATION_INFO::FindNativeAssemblyFromHostfxr(
} }
} }
if (FAILED(hr = struNativeDllLocation.Append(g_pwzAspnetcoreInProcessRequestHandlerName))) if (FAILED(hr = struNativeDllLocation.Append(libraryName)))
{ {
goto Finished; goto Finished;
} }

View File

@ -5,11 +5,6 @@
ASPNETCORE_SHIM_CONFIG::~ASPNETCORE_SHIM_CONFIG() ASPNETCORE_SHIM_CONFIG::~ASPNETCORE_SHIM_CONFIG()
{ {
if (m_ppStrArguments != NULL)
{
delete[] m_ppStrArguments;
m_ppStrArguments = NULL;
}
} }
VOID VOID
@ -38,8 +33,6 @@ ASPNETCORE_SHIM_CONFIG::GetConfig(
_In_ IHttpServer *pHttpServer, _In_ IHttpServer *pHttpServer,
_In_ HTTP_MODULE_ID pModuleId, _In_ HTTP_MODULE_ID pModuleId,
_In_ IHttpApplication *pHttpApplication, _In_ IHttpApplication *pHttpApplication,
_In_ HANDLE hEventLog,
_Out_ STRU *struExeLocation,
_Out_ ASPNETCORE_SHIM_CONFIG **ppAspNetCoreShimConfig _Out_ ASPNETCORE_SHIM_CONFIG **ppAspNetCoreShimConfig
) )
{ {
@ -47,8 +40,7 @@ ASPNETCORE_SHIM_CONFIG::GetConfig(
ASPNETCORE_SHIM_CONFIG *pAspNetCoreShimConfig = NULL; ASPNETCORE_SHIM_CONFIG *pAspNetCoreShimConfig = NULL;
STRU struHostFxrDllLocation; STRU struHostFxrDllLocation;
STRU struExeAbsolutePath; STRU struExeAbsolutePath;
BSTR* pwzArgv;
DWORD dwArgCount;
if (ppAspNetCoreShimConfig == NULL) if (ppAspNetCoreShimConfig == NULL)
{ {
hr = E_INVALIDARG; hr = E_INVALIDARG;
@ -81,32 +73,6 @@ ASPNETCORE_SHIM_CONFIG::GetConfig(
goto Finished; goto Finished;
} }
// Modify Inprocess specific configuration here.
if (pAspNetCoreShimConfig->QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS)
{
if (FAILED(hr = HOSTFXR_UTILITY::GetHostFxrParameters(
hEventLog,
pAspNetCoreShimConfig->QueryProcessPath()->QueryStr(),
pAspNetCoreShimConfig->QueryApplicationPhysicalPath()->QueryStr(),
pAspNetCoreShimConfig->QueryArguments()->QueryStr(),
&struHostFxrDllLocation,
&struExeAbsolutePath,
&dwArgCount,
&pwzArgv)))
{
goto Finished;
}
if (FAILED(hr = pAspNetCoreShimConfig->SetHostFxrFullPath(struHostFxrDllLocation.QueryStr())))
{
goto Finished;
}
pAspNetCoreShimConfig->SetHostFxrArguments(dwArgCount, pwzArgv);
struExeLocation->Copy(struExeAbsolutePath);
}
hr = pHttpApplication->GetModuleContextContainer()-> hr = pHttpApplication->GetModuleContextContainer()->
SetModuleContext(pAspNetCoreShimConfig, pModuleId); SetModuleContext(pAspNetCoreShimConfig, pModuleId);

View File

@ -119,7 +119,7 @@ inline bool IsSpace(char ch)
#include "globalmodule.h" #include "globalmodule.h"
#include "proxymodule.h" #include "proxymodule.h"
#include "applicationinfo.h" #include "applicationinfo.h"
#include "hostfxroptions.h"
FORCEINLINE FORCEINLINE
DWORD DWORD

View File

@ -2,6 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information. // Licensed under the MIT License. See License.txt in the project root for license information.
#include "precomp.hxx" #include "precomp.hxx"
#include "hostfxroptions.h"
__override __override
HRESULT HRESULT
@ -81,7 +82,6 @@ ASPNET_CORE_PROXY_MODULE::OnExecuteRequestHandler(
APPLICATION_MANAGER *pApplicationManager = NULL; APPLICATION_MANAGER *pApplicationManager = NULL;
REQUEST_NOTIFICATION_STATUS retVal = RQ_NOTIFICATION_CONTINUE; REQUEST_NOTIFICATION_STATUS retVal = RQ_NOTIFICATION_CONTINUE;
IAPPLICATION* pApplication = NULL; IAPPLICATION* pApplication = NULL;
STRU struExeLocation;
STACK_STRU(struFileName, 256); STACK_STRU(struFileName, 256);
if (g_fInShutdown) if (g_fInShutdown)
@ -90,7 +90,7 @@ ASPNET_CORE_PROXY_MODULE::OnExecuteRequestHandler(
goto Finished; goto Finished;
} }
hr = ASPNETCORE_SHIM_CONFIG::GetConfig(g_pHttpServer, g_pModuleId, pHttpContext->GetApplication(), g_hEventLog, &struExeLocation, &pConfig); hr = ASPNETCORE_SHIM_CONFIG::GetConfig(g_pHttpServer, g_pModuleId, pHttpContext->GetApplication(), &pConfig);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto Finished; goto Finished;
@ -144,7 +144,7 @@ ASPNET_CORE_PROXY_MODULE::OnExecuteRequestHandler(
} }
// make sure assmebly is loaded and application is created // make sure assmebly is loaded and application is created
hr = m_pApplicationInfo->EnsureApplicationCreated(pHttpContext, &struExeLocation); hr = m_pApplicationInfo->EnsureApplicationCreated(pHttpContext);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto Finished; goto Finished;

View File

@ -1,228 +1,230 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32"> <ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64"> <ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>x64</Platform> <Platform>x64</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|x64"> <ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>x64</Platform> <Platform>x64</Platform>
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion> <VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{55494E58-E061-4C4C-A0A8-837008E72F85}</ProjectGuid> <ProjectGuid>{55494E58-E061-4C4C-A0A8-837008E72F85}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>NewCommon</RootNamespace> <RootNamespace>NewCommon</RootNamespace>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization> <WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
</ImportGroup> </ImportGroup>
<ImportGroup Label="Shared"> <ImportGroup Label="Shared">
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
<IncludePath>C:\AspNetCoreModule\src\IISLib;$(IncludePath)</IncludePath> <IncludePath>C:\AspNetCoreModule\src\IISLib;$(IncludePath)</IncludePath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck> <SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalIncludeDirectories>..\iislib;</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\iislib;</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile> <ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>false</SDLCheck> <SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<MinimalRebuild>false</MinimalRebuild> <MinimalRebuild>false</MinimalRebuild>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
<AdditionalIncludeDirectories>..\iislib;</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\iislib;</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck> <SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
<AdditionalIncludeDirectories>..\iislib;</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\iislib;</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile> <ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck> <SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\iislib;</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\iislib;</AdditionalIncludeDirectories>
<AdditionalUsingDirectories> <AdditionalUsingDirectories>
</AdditionalUsingDirectories> </AdditionalUsingDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<ShowIncludes>false</ShowIncludes> <ShowIncludes>false</ShowIncludes>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
<Lib> <Lib>
<AdditionalLibraryDirectories>..\iislib</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>..\iislib</AdditionalLibraryDirectories>
</Lib> </Lib>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="application.h" /> <ClInclude Include="application.h" />
<ClInclude Include="fx_ver.h" /> <ClInclude Include="fx_ver.h" />
<ClInclude Include="hostfxr_utility.h" /> <ClInclude Include="hostfxroptions.h" />
<ClInclude Include="iapplication.h" /> <ClInclude Include="hostfxr_utility.h" />
<ClInclude Include="debugutil.h" /> <ClInclude Include="iapplication.h" />
<ClInclude Include="disconnectcontext.h" /> <ClInclude Include="debugutil.h" />
<ClInclude Include="environmentvariablehash.h" /> <ClInclude Include="disconnectcontext.h" />
<ClInclude Include="irequesthandler.h" /> <ClInclude Include="environmentvariablehash.h" />
<ClInclude Include="requesthandler.h" /> <ClInclude Include="irequesthandler.h" />
<ClInclude Include="requesthandler_config.h" /> <ClInclude Include="requesthandler.h" />
<ClInclude Include="resources.h" /> <ClInclude Include="requesthandler_config.h" />
<ClInclude Include="SRWLockWrapper.h" /> <ClInclude Include="resources.h" />
<ClInclude Include="stdafx.h" /> <ClInclude Include="SRWLockWrapper.h" />
<ClInclude Include="utility.h" /> <ClInclude Include="stdafx.h" />
</ItemGroup> <ClInclude Include="utility.h" />
<ItemGroup> </ItemGroup>
<ClCompile Include="fx_ver.cxx" /> <ItemGroup>
<ClCompile Include="hostfxr_utility.cpp" /> <ClCompile Include="fx_ver.cxx" />
<ClCompile Include="requesthandler_config.cpp" /> <ClCompile Include="hostfxroptions.cpp" />
<ClCompile Include="SRWLockWrapper.cpp" /> <ClCompile Include="hostfxr_utility.cpp" />
<ClCompile Include="stdafx.cpp"> <ClCompile Include="requesthandler_config.cpp" />
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> <ClCompile Include="SRWLockWrapper.cpp" />
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> <ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
</ClCompile> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<ClCompile Include="utility.cxx" /> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ItemGroup> </ClCompile>
<ItemGroup> <ClCompile Include="utility.cxx" />
<ProjectReference Include="..\IISLib\IISLib.vcxproj"> </ItemGroup>
<Project>{4787a64f-9a3e-4867-a55a-70cb4b2b2ffe}</Project> <ItemGroup>
</ProjectReference> <ProjectReference Include="..\IISLib\IISLib.vcxproj">
</ItemGroup> <Project>{4787a64f-9a3e-4867-a55a-70cb4b2b2ffe}</Project>
<ItemGroup> </ProjectReference>
<CustomBuild Include="aspnetcore_msg.mc"> </ItemGroup>
<FileType>Document</FileType> <ItemGroup>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">mc %(FullPath)</Command> <CustomBuild Include="aspnetcore_msg.mc">
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compiling Event Messages ...</Message> <FileType>Document</FileType>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).rc;%(Filename).h;MSG0409.bin</Outputs> <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">mc %(FullPath)</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">mc %(FullPath)</Command> <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compiling Event Messages ...</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Compiling Event Messages ...</Message> <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).rc;%(Filename).h;MSG0409.bin</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).rc;%(Filename).h;MSG0409.bin</Outputs> <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">mc %(FullPath)</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">mc %(FullPath)</Command> <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Compiling Event Messages ...</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compiling Event Messages ...</Message> <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).rc;%(Filename).h;MSG0409.bin</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).rc;%(Filename).h;MSG0409.bin</Outputs> <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">mc %(FullPath)</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">mc %(FullPath)</Command> <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compiling Event Messages ...</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compiling Event Messages ...</Message> <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).rc;%(Filename).h;MSG0409.bin</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).rc;%(Filename).h;MSG0409.bin</Outputs> <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">mc %(FullPath)</Command>
</CustomBuild> <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compiling Event Messages ...</Message>
</ItemGroup> <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).rc;%(Filename).h;MSG0409.bin</Outputs>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> </CustomBuild>
<ImportGroup Label="ExtensionTargets"> </ItemGroup>
</ImportGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project> </Project>

View File

@ -98,9 +98,10 @@ public:
dwResult = GetEnvironmentVariable(struNameBuffer.QueryStr(), dwResult = GetEnvironmentVariable(struNameBuffer.QueryStr(),
struValueBuffer.QueryStr(), struValueBuffer.QueryStr(),
struValueBuffer.QuerySizeCCH()); struValueBuffer.QuerySizeCCH());
if (struValueBuffer.IsEmpty())
if (dwResult <= 0)
{ {
hr = E_UNEXPECTED; hr = HRESULT_FROM_WIN32(GetLastError());
goto Finished; goto Finished;
} }
fFound = TRUE; fFound = TRUE;
@ -304,7 +305,7 @@ public:
dwResult = GetEnvironmentVariable(HOSTING_STARTUP_ASSEMBLIES_ENV_STR, dwResult = GetEnvironmentVariable(HOSTING_STARTUP_ASSEMBLIES_ENV_STR,
strStartupAssemblyEnv.QueryStr(), strStartupAssemblyEnv.QueryStr(),
strStartupAssemblyEnv.QuerySizeCCH()); strStartupAssemblyEnv.QuerySizeCCH());
if (strStartupAssemblyEnv.IsEmpty()) if (dwResult <= 0)
{ {
hr = E_UNEXPECTED; hr = E_UNEXPECTED;
goto Finished; goto Finished;
@ -317,11 +318,14 @@ public:
} }
strStartupAssemblyEnv.SyncWithBuffer(); strStartupAssemblyEnv.SyncWithBuffer();
if (strStartupAssemblyEnv.IndexOf(HOSTING_STARTUP_ASSEMBLIES_VALUE) == -1)
{
if (fFound) if (fFound)
{ {
strStartupAssemblyEnv.Append(L";"); strStartupAssemblyEnv.Append(L";");
} }
strStartupAssemblyEnv.Append(HOSTING_STARTUP_ASSEMBLIES_VALUE); strStartupAssemblyEnv.Append(HOSTING_STARTUP_ASSEMBLIES_VALUE);
}
// the environment variable was not defined, create it and add to hashtable // the environment variable was not defined, create it and add to hashtable
pHostingEntry = new ENVIRONMENT_VAR_ENTRY(); pHostingEntry = new ENVIRONMENT_VAR_ENTRY();

View File

@ -0,0 +1,102 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
#include "stdafx.h"
HRESULT HOSTFXR_OPTIONS::Create(
_In_ PCWSTR pcwzExeLocation,
_In_ PCWSTR pcwzProcessPath,
_In_ PCWSTR pcwzApplicationPhysicalPath,
_In_ PCWSTR pcwzArguments,
_In_ HANDLE hEventLog,
_Out_ std::unique_ptr<HOSTFXR_OPTIONS>& ppWrapper)
{
HRESULT hr = S_OK;
STRU struHostFxrDllLocation;
STRU struExeAbsolutePath;
STRU struExeLocation;
BSTR* pwzArgv;
DWORD dwArgCount;
if (pcwzExeLocation != NULL && FAILED(struExeLocation.Copy(pcwzExeLocation)))
{
goto Finished;
}
// If the exe was not provided by the shim, reobtain the hostfxr parameters (which finds dotnet).
if (struExeLocation.IsEmpty())
{
if (FAILED(hr = HOSTFXR_UTILITY::GetHostFxrParameters(
hEventLog,
pcwzProcessPath,
pcwzApplicationPhysicalPath,
pcwzArguments,
&struHostFxrDllLocation,
&struExeAbsolutePath,
&dwArgCount,
&pwzArgv)))
{
goto Finished;
}
}
else if (HOSTFXR_UTILITY::IsDotnetExecutable(&struExeLocation))
{
if (FAILED(hr = HOSTFXR_UTILITY::ParseHostfxrArguments(
pcwzArguments,
pcwzExeLocation,
pcwzApplicationPhysicalPath,
hEventLog,
&dwArgCount,
&pwzArgv)))
{
goto Finished;
}
}
else
{
if (FAILED(hr = HOSTFXR_UTILITY::GetStandaloneHostfxrParameters(
pcwzExeLocation,
pcwzApplicationPhysicalPath,
pcwzArguments,
hEventLog,
&struHostFxrDllLocation,
&dwArgCount,
&pwzArgv)))
{
goto Finished;
}
}
ppWrapper = std::make_unique<HOSTFXR_OPTIONS>();
if (FAILED(hr = ppWrapper->Populate(struHostFxrDllLocation.QueryStr(), struExeAbsolutePath.QueryStr(), dwArgCount, pwzArgv)))
{
goto Finished;
}
Finished:
return hr;
}
HRESULT HOSTFXR_OPTIONS::Populate(PCWSTR hostFxrLocation, PCWSTR struExeLocation, DWORD argc, BSTR argv[])
{
HRESULT hr;
m_argc = argc;
m_argv = argv;
if (FAILED(hr = m_hostFxrLocation.Copy(hostFxrLocation)))
{
goto Finished;
}
if (FAILED(hr = m_exeLocation.Copy(struExeLocation)))
{
goto Finished;
}
Finished:
return hr;
}

View File

@ -0,0 +1,58 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
#pragma once
class HOSTFXR_OPTIONS
{
public:
HOSTFXR_OPTIONS() {}
~HOSTFXR_OPTIONS()
{
delete[] m_argv;
}
DWORD
GetArgc() const
{
return m_argc;
}
BSTR*
GetArgv() const
{
return m_argv;
}
PCWSTR
GetHostFxrLocation() const
{
return m_hostFxrLocation.QueryStr();
}
PCWSTR
GetExeLocation() const
{
return m_exeLocation.QueryStr();
}
static
HRESULT Create(
_In_ PCWSTR pcwzExeLocation,
_In_ PCWSTR pcwzProcessPath,
_In_ PCWSTR pcwzApplicationPhysicalPath,
_In_ PCWSTR pcwzArguments,
_In_ HANDLE hEventLog,
_Out_ std::unique_ptr<HOSTFXR_OPTIONS>& ppWrapper);
private:
HRESULT Populate(PCWSTR hostFxrLocation, PCWSTR struExeLocation, DWORD argc, BSTR argv[]);
STRU m_exeLocation;
STRU m_hostFxrLocation;
DWORD m_argc;
BSTR* m_argv;
};

View File

@ -25,16 +25,12 @@ HRESULT
REQUESTHANDLER_CONFIG::CreateRequestHandlerConfig( REQUESTHANDLER_CONFIG::CreateRequestHandlerConfig(
_In_ IHttpServer *pHttpServer, _In_ IHttpServer *pHttpServer,
_In_ IHttpApplication *pHttpApplication, _In_ IHttpApplication *pHttpApplication,
_In_ PCWSTR pwzExeLocation,
_In_ HANDLE hEventLog,
_Out_ REQUESTHANDLER_CONFIG **ppAspNetCoreConfig _Out_ REQUESTHANDLER_CONFIG **ppAspNetCoreConfig
) )
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
REQUESTHANDLER_CONFIG *pRequestHandlerConfig = NULL; REQUESTHANDLER_CONFIG *pRequestHandlerConfig = NULL;
STRU struHostFxrDllLocation; STRU struHostFxrDllLocation;
BSTR* pwzArgv;
DWORD dwArgCount;
STRU struExeLocation; STRU struExeLocation;
if (ppAspNetCoreConfig == NULL) if (ppAspNetCoreConfig == NULL)
@ -58,60 +54,6 @@ REQUESTHANDLER_CONFIG::CreateRequestHandlerConfig(
goto Finished; goto Finished;
} }
// Modify config for inprocess.
if (pRequestHandlerConfig->QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS)
{
if (FAILED(struExeLocation.Copy(pwzExeLocation)))
{
goto Finished;
}
// If the exe was not provided by the shim, reobtain the hostfxr parameters (which finds dotnet).
if (struExeLocation.IsEmpty())
{
if (FAILED(hr = HOSTFXR_UTILITY::GetHostFxrParameters(
hEventLog,
pRequestHandlerConfig->QueryProcessPath()->QueryStr(),
pRequestHandlerConfig->QueryApplicationPhysicalPath()->QueryStr(),
pRequestHandlerConfig->QueryArguments()->QueryStr(),
&struHostFxrDllLocation,
&struExeLocation,
&dwArgCount,
&pwzArgv)))
{
goto Finished;
}
}
else if (HOSTFXR_UTILITY::IsDotnetExecutable(&struExeLocation))
{
if (FAILED(hr = HOSTFXR_UTILITY::ParseHostfxrArguments(
pRequestHandlerConfig->QueryArguments()->QueryStr(),
pwzExeLocation,
pRequestHandlerConfig->QueryApplicationPhysicalPath()->QueryStr(),
hEventLog,
&dwArgCount,
&pwzArgv)))
{
goto Finished;
}
}
else
{
if (FAILED(hr = HOSTFXR_UTILITY::GetStandaloneHostfxrParameters(
pwzExeLocation,
pRequestHandlerConfig->QueryApplicationPhysicalPath()->QueryStr(),
pRequestHandlerConfig->QueryArguments()->QueryStr(),
hEventLog,
&struHostFxrDllLocation,
&dwArgCount,
&pwzArgv)))
{
goto Finished;
}
}
pRequestHandlerConfig->SetHostFxrArguments(dwArgCount, pwzArgv);
}
DebugPrintf(ASPNETCORE_DEBUG_FLAG_INFO, DebugPrintf(ASPNETCORE_DEBUG_FLAG_INFO,
"REQUESTHANDLER_CONFIG::GetConfig, set config to ModuleContext"); "REQUESTHANDLER_CONFIG::GetConfig, set config to ModuleContext");
// set appliction info here instead of inside Populate() // set appliction info here instead of inside Populate()

View File

@ -62,8 +62,6 @@ public:
CreateRequestHandlerConfig( CreateRequestHandlerConfig(
_In_ IHttpServer *pHttpServer, _In_ IHttpServer *pHttpServer,
_In_ IHttpApplication *pHttpApplication, _In_ IHttpApplication *pHttpApplication,
_In_ PCWSTR pwzExeLocation,
_In_ HANDLE hEventLog,
_Out_ REQUESTHANDLER_CONFIG **ppAspNetCoreConfig _Out_ REQUESTHANDLER_CONFIG **ppAspNetCoreConfig
); );
@ -211,45 +209,11 @@ public:
return &m_struConfigPath; return &m_struConfigPath;
} }
CONST
PCWSTR*
QueryHostFxrArguments(
VOID
)
{
return m_ppStrArguments;
}
CONST
DWORD
QueryHostFxrArgCount(
VOID
)
{
return m_dwArgc;
}
CONST
VOID
SetHostFxrArguments(
DWORD dwArgc,
PWSTR* ppStrArguments
)
{
if (m_ppStrArguments != NULL)
{
delete[] m_ppStrArguments;
}
m_dwArgc = dwArgc;
m_ppStrArguments = ppStrArguments;
}
private: private:
// //
// private constructor // private constructor
// //
REQUESTHANDLER_CONFIG() : REQUESTHANDLER_CONFIG() :
m_fStdoutLogEnabled(FALSE), m_fStdoutLogEnabled(FALSE),
m_pEnvironmentVariables(NULL), m_pEnvironmentVariables(NULL),

View File

@ -32,4 +32,4 @@
#include "aspnetcore_msg.h" #include "aspnetcore_msg.h"
#include "fx_ver.h" #include "fx_ver.h"
#include "hostfxr_utility.h" #include "hostfxr_utility.h"
#include "hostfxroptions.h"

View File

@ -113,13 +113,13 @@ CreateApplication(
// Initialze some global variables here // Initialze some global variables here
InitializeGlobalConfiguration(pServer); InitializeGlobalConfiguration(pServer);
hr = REQUESTHANDLER_CONFIG::CreateRequestHandlerConfig(pServer, pHttpContext->GetApplication(), pwzExeLocation, g_hEventLog, &pConfig); hr = REQUESTHANDLER_CONFIG::CreateRequestHandlerConfig(pServer, pHttpContext->GetApplication(), &pConfig);
if (FAILED(hr)) if (FAILED(hr))
{ {
return hr; return hr;
} }
pApplication = new IN_PROCESS_APPLICATION(pServer, pConfig); pApplication = new IN_PROCESS_APPLICATION(pServer, pConfig, pwzExeLocation);
if (pApplication == NULL) if (pApplication == NULL)
{ {
hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);

View File

@ -1,10 +1,13 @@
#include "..\precomp.hxx" #include "..\precomp.hxx"
#include "hostfxroptions.h"
IN_PROCESS_APPLICATION* IN_PROCESS_APPLICATION::s_Application = NULL; IN_PROCESS_APPLICATION* IN_PROCESS_APPLICATION::s_Application = NULL;
hostfxr_main_fn IN_PROCESS_APPLICATION::s_fMainCallback = NULL;
IN_PROCESS_APPLICATION::IN_PROCESS_APPLICATION( IN_PROCESS_APPLICATION::IN_PROCESS_APPLICATION(
IHttpServer* pHttpServer, IHttpServer *pHttpServer,
REQUESTHANDLER_CONFIG *pConfig) : REQUESTHANDLER_CONFIG *pConfig,
PCWSTR pDotnetExeLocation) :
m_pHttpServer(pHttpServer), m_pHttpServer(pHttpServer),
m_ProcessExitCode(0), m_ProcessExitCode(0),
m_hLogFileHandle(INVALID_HANDLE_VALUE), m_hLogFileHandle(INVALID_HANDLE_VALUE),
@ -16,7 +19,8 @@ IN_PROCESS_APPLICATION::IN_PROCESS_APPLICATION(
m_fInitialized(FALSE), m_fInitialized(FALSE),
m_fShutdownCalledFromNative(FALSE), m_fShutdownCalledFromNative(FALSE),
m_fShutdownCalledFromManaged(FALSE), m_fShutdownCalledFromManaged(FALSE),
m_srwLock() m_srwLock(),
m_pstrDotnetExeLocation(pDotnetExeLocation)
{ {
// is it guaranteed that we have already checked app offline at this point? // is it guaranteed that we have already checked app offline at this point?
// If so, I don't think there is much to do here. // If so, I don't think there is much to do here.
@ -116,7 +120,7 @@ Finished:
// Managed layer may block the shutdown and lead to shutdown timeout // Managed layer may block the shutdown and lead to shutdown timeout
// Assumption: only one inprocess application is hosted. // Assumption: only one inprocess application is hosted.
// Call process exit to force shutdown // Call process exit to force shutdown
// //
exit(hr); exit(hr);
} }
} }
@ -262,7 +266,6 @@ IN_PROCESS_APPLICATION::Recycle(
// IISExpress scenario // IISExpress scenario
// Shutdown the managed application and call exit to terminate current process // Shutdown the managed application and call exit to terminate current process
ShutDown(); ShutDown();
exit(0);
} }
} }
@ -808,33 +811,55 @@ IN_PROCESS_APPLICATION::ExecuteApplication(
) )
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
HMODULE hModule; HMODULE hModule = nullptr;
DWORD hostfxrArgc = 0;
BSTR *hostfxrArgv = NULL;
hostfxr_main_fn pProc; hostfxr_main_fn pProc;
std::unique_ptr<HOSTFXR_OPTIONS> hostFxrOptions = NULL;
DBG_ASSERT(m_status == APPLICATION_STATUS::STARTING); DBG_ASSERT(m_status == APPLICATION_STATUS::STARTING);
// hostfxr should already be loaded by the shim. If not, then we will need pProc = s_fMainCallback;
// to load it ourselves by finding hostfxr again. if (pProc == nullptr)
hModule = LoadLibraryW(L"hostfxr.dll");
if (hModule == NULL)
{ {
// .NET Core not installed (we can log a more detailed error message here) // hostfxr should already be loaded by the shim. If not, then we will need
hr = ERROR_BAD_ENVIRONMENT; // to load it ourselves by finding hostfxr again.
goto Finished; hModule = LoadLibraryW(L"hostfxr.dll");
}
// Get the entry point for main if (hModule == NULL)
pProc = (hostfxr_main_fn)GetProcAddress(hModule, "hostfxr_main"); {
if (pProc == NULL) // .NET Core not installed (we can log a more detailed error message here)
{ hr = ERROR_BAD_ENVIRONMENT;
hr = ERROR_BAD_ENVIRONMENT; goto Finished;
goto Finished; }
}
if (FAILED(hr = SetEnvironementVariablesOnWorkerProcess())) // Get the entry point for main
{ pProc = (hostfxr_main_fn)GetProcAddress(hModule, "hostfxr_main");
goto Finished; if (pProc == NULL)
{
hr = ERROR_BAD_ENVIRONMENT;
goto Finished;
}
if (FAILED(hr = HOSTFXR_OPTIONS::Create(
m_pstrDotnetExeLocation,
m_pConfig->QueryProcessPath()->QueryStr(),
m_pConfig->QueryApplicationPhysicalPath()->QueryStr(),
m_pConfig->QueryArguments()->QueryStr(),
g_hEventLog,
hostFxrOptions
)))
{
goto Finished;
}
hostfxrArgc = hostFxrOptions->GetArgc();
hostfxrArgv = hostFxrOptions->GetArgv();
if (FAILED(hr = SetEnvironementVariablesOnWorkerProcess()))
{
goto Finished;
}
} }
// There can only ever be a single instance of .NET Core // There can only ever be a single instance of .NET Core
@ -845,7 +870,7 @@ IN_PROCESS_APPLICATION::ExecuteApplication(
// set the callbacks // set the callbacks
s_Application = this; s_Application = this;
hr = RunDotnetApplication(m_pConfig->QueryHostFxrArgCount(), m_pConfig->QueryHostFxrArguments(), pProc); hr = RunDotnetApplication(hostfxrArgc, hostfxrArgv, pProc);
Finished: Finished:

View File

@ -11,7 +11,10 @@ typedef REQUEST_NOTIFICATION_STATUS(WINAPI * PFN_MANAGED_CONTEXT_HANDLER)(void *
class IN_PROCESS_APPLICATION : public APPLICATION class IN_PROCESS_APPLICATION : public APPLICATION
{ {
public: public:
IN_PROCESS_APPLICATION(IHttpServer* pHttpServer, REQUESTHANDLER_CONFIG *pConfig); IN_PROCESS_APPLICATION(
IHttpServer* pHttpServer,
REQUESTHANDLER_CONFIG *pConfig,
PCWSTR pDotnetExeLocation);
~IN_PROCESS_APPLICATION(); ~IN_PROCESS_APPLICATION();
@ -102,6 +105,12 @@ public:
m_fShutdownCalledFromManaged = TRUE; m_fShutdownCalledFromManaged = TRUE;
} }
static
VOID SetMainCallback(hostfxr_main_fn mainCallback)
{
s_fMainCallback = mainCallback;
}
static static
IN_PROCESS_APPLICATION* IN_PROCESS_APPLICATION*
GetInstance( GetInstance(
@ -176,10 +185,15 @@ private:
HANDLE m_hErrThread; HANDLE m_hErrThread;
CHAR m_pzFileContents[4096] = { 0 }; CHAR m_pzFileContents[4096] = { 0 };
DWORD m_dwStdErrReadTotal; DWORD m_dwStdErrReadTotal;
PCWSTR m_pstrDotnetExeLocation;
static IN_PROCESS_APPLICATION* s_Application; static IN_PROCESS_APPLICATION* s_Application;
REQUESTHANDLER_CONFIG* m_pConfig; REQUESTHANDLER_CONFIG* m_pConfig;
// Allows to override call to hostfxr_main with custome callback
// used in testing
static hostfxr_main_fn s_fMainCallback;
VOID VOID
SetStdOut( SetStdOut(
VOID VOID

View File

@ -442,4 +442,11 @@ http_stop_incoming_requests()
IN_PROCESS_APPLICATION::GetInstance()->StopIncomingRequests(); IN_PROCESS_APPLICATION::GetInstance()->StopIncomingRequests();
} }
EXTERN_C __MIDL_DECLSPEC_DLLEXPORT
VOID
set_main_handler(_In_ hostfxr_main_fn main)
{
IN_PROCESS_APPLICATION::SetMainCallback(main);
}
// End of export // End of export

View File

@ -285,10 +285,12 @@ CreateApplication(
HRESULT hr = S_OK; HRESULT hr = S_OK;
IAPPLICATION *pApplication = NULL; IAPPLICATION *pApplication = NULL;
REQUESTHANDLER_CONFIG *pConfig = NULL; REQUESTHANDLER_CONFIG *pConfig = NULL;
UNREFERENCED_PARAMETER(pwzExeLocation);
// Initialze some global variables here // Initialze some global variables here
InitializeGlobalConfiguration(pServer); InitializeGlobalConfiguration(pServer);
hr = REQUESTHANDLER_CONFIG::CreateRequestHandlerConfig(pServer, pHttpContext->GetApplication(), pwzExeLocation, g_hEventLog, &pConfig); hr = REQUESTHANDLER_CONFIG::CreateRequestHandlerConfig(pServer, pHttpContext->GetApplication(), &pConfig);
if (FAILED(hr)) if (FAILED(hr))
{ {
return hr; return hr;

View File

@ -136,6 +136,8 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
} }
_memoryPool.Dispose(); _memoryPool.Dispose();
GC.SuppressFinalize(this);
} }
private static NativeMethods.REQUEST_NOTIFICATION_STATUS HandleRequest(IntPtr pInProcessHandler, IntPtr pvRequestContext) private static NativeMethods.REQUEST_NOTIFICATION_STATUS HandleRequest(IntPtr pInProcessHandler, IntPtr pvRequestContext)

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.IIS
private const string KERNEL32 = "kernel32.dll"; private const string KERNEL32 = "kernel32.dll";
private const string AspNetCoreModuleDll = "aspnetcorev2_inprocess.dll"; internal const string AspNetCoreModuleDll = "aspnetcorev2_inprocess.dll";
[DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)] [DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)]

View File

@ -0,0 +1,201 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
IIS configuration sections.
For schema documentation, see
%windir%\system32\inetsrv\config\schema\IIS_schema.xml.
Please make a backup of this file before making any changes to it.
-->
<configuration>
<!--
The <configSections> section controls the registration of sections.
Section is the basic unit of deployment, locking, searching and
containment for configuration settings.
Every section belongs to one section group.
A section group is a container of logically-related sections.
Sections cannot be nested.
Section groups may be nested.
<section
name="" [Required, Collection Key] [XML name of the section]
allowDefinition="Everywhere" [MachineOnly|MachineToApplication|AppHostOnly|Everywhere] [Level where it can be set]
overrideModeDefault="Allow" [Allow|Deny] [Default delegation mode]
allowLocation="true" [true|false] [Allowed in location tags]
/>
The recommended way to unlock sections is by using a location tag:
<location path="Default Web Site" overrideMode="Allow">
<system.webServer>
<asp />
</system.webServer>
</location>
-->
<configSections>
<sectionGroup name="system.applicationHost">
<section name="applicationPools" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
<section name="configHistory" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
<section name="customMetadata" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
<section name="listenerAdapters" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
<section name="log" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
<section name="serviceAutoStartProviders" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
<section name="sites" overrideModeDefault="Allow" />
<section name="webLimits" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
</sectionGroup>
<sectionGroup name="system.webServer">
<section name="asp" overrideModeDefault="Deny" />
<section name="caching" overrideModeDefault="Allow" />
<section name="aspNetCore" overrideModeDefault="Allow" />
<section name="cgi" overrideModeDefault="Deny" />
<section name="defaultDocument" overrideModeDefault="Allow" />
<section name="directoryBrowse" overrideModeDefault="Allow" />
<section name="fastCgi" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
<section name="globalModules" overrideModeDefault="Allow" />
<section name="handlers" allowDefinition="MachineToApplication" overrideModeDefault="Allow" />
<section name="httpCompression" overrideModeDefault="Allow" />
<section name="httpErrors" overrideModeDefault="Allow" />
<section name="httpLogging" overrideModeDefault="Deny" />
<section name="httpProtocol" overrideModeDefault="Allow" />
<section name="httpRedirect" overrideModeDefault="Allow" />
<section name="httpTracing" overrideModeDefault="Deny" />
<section name="isapiFilters" allowDefinition="MachineToApplication" overrideModeDefault="Deny" />
<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Deny" />
<section name="applicationInitialization" allowDefinition="MachineToApplication" overrideModeDefault="Allow" />
<section name="odbcLogging" overrideModeDefault="Deny" />
<sectionGroup name="security">
<section name="access" overrideModeDefault="Deny" />
<section name="applicationDependencies" overrideModeDefault="Deny" />
<sectionGroup name="authentication">
<section name="anonymousAuthentication" overrideModeDefault="Deny" />
<section name="basicAuthentication" overrideModeDefault="Deny" />
<section name="clientCertificateMappingAuthentication" overrideModeDefault="Deny" />
<section name="digestAuthentication" overrideModeDefault="Deny" />
<section name="iisClientCertificateMappingAuthentication" overrideModeDefault="Deny" />
<section name="windowsAuthentication" overrideModeDefault="Deny" />
</sectionGroup>
<section name="authorization" overrideModeDefault="Allow" />
<section name="ipSecurity" overrideModeDefault="Deny" />
<section name="dynamicIpSecurity" overrideModeDefault="Deny" />
<section name="isapiCgiRestriction" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
<section name="requestFiltering" overrideModeDefault="Allow" />
</sectionGroup>
<section name="serverRuntime" overrideModeDefault="Deny" />
<section name="serverSideInclude" overrideModeDefault="Deny" />
<section name="staticContent" overrideModeDefault="Allow" />
<sectionGroup name="tracing">
<section name="traceFailedRequests" overrideModeDefault="Allow" />
<section name="traceProviderDefinitions" overrideModeDefault="Deny" />
</sectionGroup>
<section name="urlCompression" overrideModeDefault="Allow" />
<section name="validation" overrideModeDefault="Allow" />
<sectionGroup name="webdav">
<section name="globalSettings" overrideModeDefault="Deny" />
<section name="authoring" overrideModeDefault="Deny" />
<section name="authoringRules" overrideModeDefault="Deny" />
</sectionGroup>
<section name="webSocket" overrideModeDefault="Deny" />
</sectionGroup>
<sectionGroup name="system.ftpServer">
<section name="log" overrideModeDefault="Deny" allowDefinition="AppHostOnly" />
<section name="firewallSupport" overrideModeDefault="Deny" allowDefinition="AppHostOnly" />
<section name="caching" overrideModeDefault="Deny" allowDefinition="AppHostOnly" />
<section name="providerDefinitions" overrideModeDefault="Deny" />
<sectionGroup name="security">
<section name="ipSecurity" overrideModeDefault="Deny" />
<section name="requestFiltering" overrideModeDefault="Deny" />
<section name="authorization" overrideModeDefault="Deny" />
<section name="authentication" overrideModeDefault="Deny" />
</sectionGroup>
<section name="serverRuntime" overrideModeDefault="Deny" allowDefinition="AppHostOnly" />
</sectionGroup>
</configSections>
<system.applicationHost>
<applicationPools>
<add name="DefaultAppPool" />
<applicationPoolDefaults managedRuntimeVersion="v4.0">
<processModel identityType="ApplicationPoolIdentity" />
</applicationPoolDefaults>
</applicationPools>
<!--
The <customMetadata> section is used internally by the Admin Base Objects
(ABO) Compatibility component. Please do not modify its content.
-->
<customMetadata />
<!--
The <listenerAdapters> section defines the protocols with which the
Windows Process Activation Service (WAS) binds.
-->
<listenerAdapters>
<add name="http" />
</listenerAdapters>
<log>
<centralBinaryLogFile enabled="false" />
<centralW3CLogFile enabled="false" />
</log>
<sites>
<site name="Default Web Site" id="1">
<application path="/">
<virtualDirectory path="/" physicalPath="." />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:50691:localhost" />
</bindings>
</site>
<applicationDefaults applicationPool="DefaultAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
<webLimits />
</system.applicationHost>
<system.webServer>
<!--
The <globalModules> section defines all native-code modules.
To enable a module, specify it in the <modules> section.
-->
<globalModules>
<add name="UriCacheModule" image="%windir%\System32\inetsrv\cachuri.dll" />
<add name="ProtocolSupportModule" image="%windir%\System32\inetsrv\protsup.dll" />
<add name="AnonymousAuthenticationModule" image="%windir%\System32\inetsrv\authanon.dll" />
<add name="AspNetCoreModuleV2" image="aspnetcorev2.dll" />
</globalModules>
<handlers accessPolicy="Read, Script">
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<modules>
<add name="AnonymousAuthenticationModule" lockItem="true" />
<add name="AspNetCoreModuleV2" lockItem="true" />
</modules>
<aspNetCore processPath="" arguments="" hostingModel="inprocess"/>
</system.webServer>
</configuration>

View File

@ -6,17 +6,33 @@
<ItemGroup> <ItemGroup>
<Content Include="AppHostConfig\*.config" CopyToOutputDirectory="PreserveNewest" /> <Content Include="AppHostConfig\*.config" CopyToOutputDirectory="PreserveNewest" />
<Content Include="Properties\launchSettings.json">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Server.IIS\Microsoft.AspNetCore.Server.IIS.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" /> <ProjectReference Include="..\..\src\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" />
<ProjectReference Include="..\WebSites\**\*.csproj"> <ProjectReference Include="..\WebSites\**\*.csproj">
<ReferenceOutputAssembly>False</ReferenceOutputAssembly> <ReferenceOutputAssembly>False</ReferenceOutputAssembly>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\InProcessRequestHandler\bin\$(Configuration)\x64\aspnetcorev2_inprocess.dll" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\InProcessRequestHandler\bin\$(Configuration)\x64\aspnetcorev2_inprocess.pdb" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\AspNetCore\bin\$(Configuration)\x64\aspnetcorev2.dll" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\AspNetCore\bin\$(Configuration)\x64\aspnetcorev2.pdb" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
</ItemGroup>
<ItemGroup>
<None Remove="AppHostConfig\TestServer.config" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Server.IntegrationTesting" Version="$(MicrosoftAspNetCoreServerIntegrationTestingPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Server.IntegrationTesting" Version="$(MicrosoftAspNetCoreServerIntegrationTestingPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(MicrosoftAspNetCoreHostingPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" Version="$(MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion)" /> <PackageReference Include="Microsoft.Extensions.CommandLineUtils.Sources" Version="$(MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingPackageVersion)" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="$(MicrosoftExtensionsLoggingTestingPackageVersion)" /> <PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="$(MicrosoftExtensionsLoggingTestingPackageVersion)" />
@ -26,4 +42,10 @@
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualStudioPackageVersion)" /> <PackageReference Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualStudioPackageVersion)" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Update="AppHostConfig\TestServer.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,41 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using IISIntegration.FunctionalTests.Utilities;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace IISIntegration.FunctionalTests.Inprocess
{
[SkipIfHostableWebCoreNotAvailible]
public class TestServerTest: LoggedTest
{
public TestServerTest(ITestOutputHelper output = null) : base(output)
{
}
[ConditionalFact]
public async Task Test()
{
var helloWorld = "Hello World";
var expectedPath = "/Path";
string path = null;
using (var testServer = await TestServer.Create(ctx => {
path = ctx.Request.Path.ToString();
return ctx.Response.WriteAsync(helloWorld);
}, LoggerFactory))
{
var result = await testServer.HttpClient.GetAsync(expectedPath);
Assert.Equal(helloWorld, await result.Content.ReadAsStringAsync());
Assert.Equal(expectedPath, path);
}
}
}
}

View File

@ -0,0 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using Microsoft.AspNetCore.Testing.xunit;
namespace IISIntegration.FunctionalTests.Utilities
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public sealed class SkipIfHostableWebCoreNotAvailibleAttribute : Attribute, ITestCondition
{
public bool IsMet { get; } = File.Exists(TestServer.HostableWebCoreLocation);
public string SkipReason { get; } = $"Hostable Web Core not availible, {TestServer.HostableWebCoreLocation} not found.";
}
}

View File

@ -0,0 +1,144 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace IISIntegration.FunctionalTests.Utilities
{
public class TestServer: IDisposable, IStartup
{
private const string InProcessHandlerDll = "aspnetcorev2_inprocess.dll";
private const string AspNetCoreModuleDll = "aspnetcorev2.dll";
private const string HWebCoreDll = "hwebcore.dll";
internal static string HostableWebCoreLocation => Environment.ExpandEnvironmentVariables($@"%windir%\system32\inetsrv\{HWebCoreDll}");
private static readonly SemaphoreSlim WebCoreLock = new SemaphoreSlim(1, 1);
// Currently this is hardcoded in TestServer.config
private static readonly int BasePort = 50691;
private static readonly Uri BaseUri = new Uri("http://localhost:" + BasePort);
private readonly TaskCompletionSource<object> _startedTaskCompletionSource = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
private readonly Action<IApplicationBuilder> _appBuilder;
private readonly ILoggerFactory _loggerFactory;
public HttpClient HttpClient { get; }
public TestConnection CreateConnection() => new TestConnection(BasePort);
private IWebHost _host;
private TestServer(Action<IApplicationBuilder> appBuilder, ILoggerFactory loggerFactory)
{
_appBuilder = appBuilder;
_loggerFactory = loggerFactory;
HttpClient = new HttpClient(new LoggingHandler(new SocketsHttpHandler(), _loggerFactory.CreateLogger<TestServer>()))
{
BaseAddress = BaseUri
};
}
public static async Task<TestServer> Create(Action<IApplicationBuilder> appBuilder, ILoggerFactory loggerFactory)
{
await WebCoreLock.WaitAsync();
var server = new TestServer(appBuilder, loggerFactory);
server.Start();
await server.HttpClient.GetAsync("/start");
await server._startedTaskCompletionSource.Task;
return server;
}
public static Task<TestServer> Create(RequestDelegate app, ILoggerFactory loggerFactory)
{
return Create(builder => builder.Run(app), loggerFactory);
}
private void Start()
{
LoadLibrary(HostableWebCoreLocation);
LoadLibrary(InProcessHandlerDll);
LoadLibrary(AspNetCoreModuleDll);
set_main_handler(Main);
var startResult = WebCoreActivate(Path.GetFullPath("AppHostConfig/TestServer.config"), null, "Instance");
if (startResult != 0)
{
throw new InvalidOperationException($"Error while running WebCoreActivate: {startResult}");
}
}
private int Main(IntPtr argc, IntPtr argv)
{
_host = new WebHostBuilder()
.UseIIS()
.ConfigureServices(services => {
services.AddSingleton<IStartup>(this);
services.AddSingleton<ILoggerFactory>(_loggerFactory);
})
.UseSetting(WebHostDefaults.ApplicationKey, typeof(TestServer).GetTypeInfo().Assembly.FullName)
.Build();
var doneEvent = new ManualResetEventSlim();
var lifetime = _host.Services.GetService<IApplicationLifetime>();
lifetime.ApplicationStopping.Register(() => doneEvent.Set());
_host.Start();
_startedTaskCompletionSource.SetResult(null);
doneEvent.Wait();
_host.Dispose();
return 0;
}
public void Dispose()
{
HttpClient.Dispose();
WebCoreShutdown(false);
WebCoreLock.Release();
}
public IServiceProvider ConfigureServices(IServiceCollection services)
{
return services.BuildServiceProvider();
}
public void Configure(IApplicationBuilder app)
{
app.Map("/start", builder => builder.Run(context => context.Response.WriteAsync("Done")));
_appBuilder(app);
}
private delegate int hostfxr_main_fn(IntPtr argc, IntPtr argv);
[DllImport(HWebCoreDll)]
private static extern int WebCoreActivate(
[In, MarshalAs(UnmanagedType.LPWStr)]
string appHostConfigPath,
[In, MarshalAs(UnmanagedType.LPWStr)]
string rootWebConfigPath,
[In, MarshalAs(UnmanagedType.LPWStr)]
string instanceName);
[DllImport(HWebCoreDll)]
private static extern int WebCoreShutdown(bool immediate);
[DllImport(InProcessHandlerDll)]
private static extern int set_main_handler(hostfxr_main_fn main);
[DllImport("kernel32", SetLastError=true, CharSet = CharSet.Ansi)]
private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName);
}
}