Move in-process server implementation to IIS.Server (#837)
This commit is contained in:
parent
0e7effa376
commit
34c797a46b
|
|
@ -1,4 +1,4 @@
|
||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<Import Project="..\..\build\testsite.props" />
|
<Import Project="..\..\build\testsite.props" />
|
||||||
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" />
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Server.IIS\Microsoft.AspNetCore.Server.IIS.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.AspNetCore.Server.IIS;
|
using Microsoft.AspNetCore.Server.IIS;
|
||||||
using Microsoft.AspNetCore.Server.IISIntegration;
|
|
||||||
|
|
||||||
namespace NativeIISSample
|
namespace NativeIISSample
|
||||||
{
|
{
|
||||||
|
|
@ -42,7 +41,7 @@ namespace NativeIISSample
|
||||||
await context.Response.WriteAsync(Environment.NewLine);
|
await context.Response.WriteAsync(Environment.NewLine);
|
||||||
|
|
||||||
await context.Response.WriteAsync("User: " + context.User.Identity.Name + Environment.NewLine);
|
await context.Response.WriteAsync("User: " + context.User.Identity.Name + Environment.NewLine);
|
||||||
var scheme = await authSchemeProvider.GetSchemeAsync(IISDefaults.AuthenticationScheme);
|
var scheme = await authSchemeProvider.GetSchemeAsync(IISServerDefaults.AuthenticationScheme);
|
||||||
await context.Response.WriteAsync("DisplayName: " + scheme?.DisplayName + Environment.NewLine);
|
await context.Response.WriteAsync("DisplayName: " + scheme?.DisplayName + Environment.NewLine);
|
||||||
|
|
||||||
await context.Response.WriteAsync(Environment.NewLine);
|
await context.Response.WriteAsync(Environment.NewLine);
|
||||||
|
|
@ -99,7 +98,7 @@ namespace NativeIISSample
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var host = new WebHostBuilder()
|
var host = new WebHostBuilder()
|
||||||
.UseIISIntegration()
|
.UseIIS()
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
// 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.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.IISIntegration.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||||
|
|
||||||
|
|
@ -6,7 +6,7 @@ using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
// TODO redudant file, remove
|
// TODO redudant file, remove
|
||||||
// See https://github.com/aspnet/IISIntegration/issues/426
|
// See https://github.com/aspnet/IISIntegration/issues/426
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
internal unsafe struct IISConfigurationData
|
internal unsafe struct IISConfigurationData
|
||||||
|
|
@ -6,16 +6,16 @@ using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.AspNetCore.Http.Features.Authentication;
|
using Microsoft.AspNetCore.Http.Features.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Server.IIS.Core.IO;
|
||||||
using Microsoft.AspNetCore.WebUtilities;
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal partial class IISHttpContext : IFeatureCollection,
|
internal partial class IISHttpContext : IFeatureCollection,
|
||||||
IHttpRequestFeature,
|
IHttpRequestFeature,
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal partial class IISHttpContext
|
internal partial class IISHttpContext
|
||||||
{
|
{
|
||||||
|
|
@ -5,7 +5,7 @@ using System.Globalization;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal partial class IISHttpContext : IHttpConnectionFeature
|
internal partial class IISHttpContext : IHttpConnectionFeature
|
||||||
{
|
{
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal partial class IISHttpContext : IHttpRequestIdentifierFeature
|
internal partial class IISHttpContext : IHttpRequestIdentifierFeature
|
||||||
{
|
{
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Buffers;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal partial class IISHttpContext
|
internal partial class IISHttpContext
|
||||||
{
|
{
|
||||||
|
|
@ -5,7 +5,6 @@ using System;
|
||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Pipelines;
|
using System.IO.Pipelines;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
@ -18,10 +17,10 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.HttpSys.Internal;
|
using Microsoft.AspNetCore.HttpSys.Internal;
|
||||||
|
using Microsoft.AspNetCore.Server.IIS.Core.IO;
|
||||||
using Microsoft.AspNetCore.WebUtilities;
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal abstract partial class IISHttpContext : NativeRequestContext, IDisposable
|
internal abstract partial class IISHttpContext : NativeRequestContext, IDisposable
|
||||||
{
|
{
|
||||||
|
|
@ -32,7 +31,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||||
|
|
||||||
protected readonly IntPtr _pInProcessHandler;
|
protected readonly IntPtr _pInProcessHandler;
|
||||||
|
|
||||||
private readonly IISOptions _options;
|
private readonly IISServerOptions _options;
|
||||||
|
|
||||||
private volatile bool _hasResponseStarted;
|
private volatile bool _hasResponseStarted;
|
||||||
private volatile bool _hasRequestReadingStarted;
|
private volatile bool _hasRequestReadingStarted;
|
||||||
|
|
@ -64,7 +63,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||||
private const string BasicString = "Basic";
|
private const string BasicString = "Basic";
|
||||||
|
|
||||||
|
|
||||||
internal unsafe IISHttpContext(MemoryPool<byte> memoryPool, IntPtr pInProcessHandler, IISOptions options, IISHttpServer server)
|
internal unsafe IISHttpContext(MemoryPool<byte> memoryPool, IntPtr pInProcessHandler, IISServerOptions options, IISHttpServer server)
|
||||||
: base((HttpApiTypes.HTTP_REQUEST*)NativeMethods.HttpGetRawRequest(pInProcessHandler))
|
: base((HttpApiTypes.HTTP_REQUEST*)NativeMethods.HttpGetRawRequest(pInProcessHandler))
|
||||||
{
|
{
|
||||||
_memoryPool = memoryPool;
|
_memoryPool = memoryPool;
|
||||||
|
|
@ -8,13 +8,13 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting.Server;
|
using Microsoft.AspNetCore.Hosting.Server;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal class IISHttpContextOfT<TContext> : IISHttpContext
|
internal class IISHttpContextOfT<TContext> : IISHttpContext
|
||||||
{
|
{
|
||||||
private readonly IHttpApplication<TContext> _application;
|
private readonly IHttpApplication<TContext> _application;
|
||||||
|
|
||||||
public IISHttpContextOfT(MemoryPool<byte> memoryPool, IHttpApplication<TContext> application, IntPtr pInProcessHandler, IISOptions options, IISHttpServer server)
|
public IISHttpContextOfT(MemoryPool<byte> memoryPool, IHttpApplication<TContext> application, IntPtr pInProcessHandler, IISServerOptions options, IISHttpServer server)
|
||||||
: base(memoryPool, pInProcessHandler, options, server)
|
: base(memoryPool, pInProcessHandler, options, server)
|
||||||
{
|
{
|
||||||
_application = application;
|
_application = application;
|
||||||
|
|
@ -6,7 +6,7 @@ using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal class IISHttpRequestBody : Stream
|
internal class IISHttpRequestBody : Stream
|
||||||
{
|
{
|
||||||
|
|
@ -6,7 +6,7 @@ using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal class IISHttpResponseBody : Stream
|
internal class IISHttpResponseBody : Stream
|
||||||
{
|
{
|
||||||
|
|
@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Hosting.Server;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal class IISHttpServer : IServer
|
internal class IISHttpServer : IServer
|
||||||
{
|
{
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||||
private GCHandle _httpServerHandle;
|
private GCHandle _httpServerHandle;
|
||||||
private readonly IApplicationLifetime _applicationLifetime;
|
private readonly IApplicationLifetime _applicationLifetime;
|
||||||
private readonly IAuthenticationSchemeProvider _authentication;
|
private readonly IAuthenticationSchemeProvider _authentication;
|
||||||
private readonly IISOptions _options;
|
private readonly IISServerOptions _options;
|
||||||
|
|
||||||
private volatile int _stopping;
|
private volatile int _stopping;
|
||||||
private bool Stopping => _stopping == 1;
|
private bool Stopping => _stopping == 1;
|
||||||
|
|
@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||||
return _websocketAvailable.Value;
|
return _websocketAvailable.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IISHttpServer(IApplicationLifetime applicationLifetime, IAuthenticationSchemeProvider authentication, IOptions<IISOptions> options)
|
public IISHttpServer(IApplicationLifetime applicationLifetime, IAuthenticationSchemeProvider authentication, IOptions<IISServerOptions> options)
|
||||||
{
|
{
|
||||||
_applicationLifetime = applicationLifetime;
|
_applicationLifetime = applicationLifetime;
|
||||||
_authentication = authentication;
|
_authentication = authentication;
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||||
|
|
||||||
if (_options.ForwardWindowsAuthentication)
|
if (_options.ForwardWindowsAuthentication)
|
||||||
{
|
{
|
||||||
authentication.AddScheme(new AuthenticationScheme(IISDefaults.AuthenticationScheme, _options.AuthenticationDisplayName, typeof(IISServerAuthenticationHandler)));
|
authentication.AddScheme(new AuthenticationScheme(IISServerDefaults.AuthenticationScheme, _options.AuthenticationDisplayName, typeof(IISServerAuthenticationHandler)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,10 +197,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||||
{
|
{
|
||||||
private readonly IHttpApplication<T> _application;
|
private readonly IHttpApplication<T> _application;
|
||||||
private readonly MemoryPool<byte> _memoryPool;
|
private readonly MemoryPool<byte> _memoryPool;
|
||||||
private readonly IISOptions _options;
|
private readonly IISServerOptions _options;
|
||||||
private readonly IISHttpServer _server;
|
private readonly IISHttpServer _server;
|
||||||
|
|
||||||
public IISContextFactory(MemoryPool<byte> memoryPool, IHttpApplication<T> application, IISOptions options, IISHttpServer server)
|
public IISContextFactory(MemoryPool<byte> memoryPool, IHttpApplication<T> application, IISServerOptions options, IISHttpServer server)
|
||||||
{
|
{
|
||||||
_application = application;
|
_application = application;
|
||||||
_memoryPool = memoryPool;
|
_memoryPool = memoryPool;
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
public class IISServerAuthenticationHandler : IAuthenticationHandler
|
public class IISServerAuthenticationHandler : IAuthenticationHandler
|
||||||
{
|
{
|
||||||
|
|
@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Hosting.Server;
|
using Microsoft.AspNetCore.Hosting.Server;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal class IISServerSetupFilter : IStartupFilter
|
internal class IISServerSetupFilter : IStartupFilter
|
||||||
{
|
{
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
||||||
{
|
{
|
||||||
internal partial class AsyncIOEngine
|
internal partial class AsyncIOEngine
|
||||||
{
|
{
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
||||||
{
|
{
|
||||||
internal partial class AsyncIOEngine
|
internal partial class AsyncIOEngine
|
||||||
{
|
{
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.HttpSys.Internal;
|
using Microsoft.AspNetCore.HttpSys.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
||||||
{
|
{
|
||||||
internal partial class AsyncIOEngine
|
internal partial class AsyncIOEngine
|
||||||
{
|
{
|
||||||
|
|
@ -8,7 +8,7 @@ using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
||||||
{
|
{
|
||||||
internal partial class AsyncIOEngine : IAsyncIOEngine
|
internal partial class AsyncIOEngine : IAsyncIOEngine
|
||||||
{
|
{
|
||||||
|
|
@ -7,7 +7,7 @@ using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks.Sources;
|
using System.Threading.Tasks.Sources;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
||||||
{
|
{
|
||||||
internal abstract class AsyncIOOperation: IValueTaskSource<int>, IValueTaskSource
|
internal abstract class AsyncIOOperation: IValueTaskSource<int>, IValueTaskSource
|
||||||
{
|
{
|
||||||
|
|
@ -5,7 +5,7 @@ using System;
|
||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
using Microsoft.AspNetCore.HttpSys.Internal;
|
using Microsoft.AspNetCore.HttpSys.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
||||||
{
|
{
|
||||||
internal abstract class AsyncWriteOperationBase : AsyncIOOperation
|
internal abstract class AsyncWriteOperationBase : AsyncIOOperation
|
||||||
{
|
{
|
||||||
|
|
@ -5,7 +5,7 @@ using System;
|
||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
||||||
{
|
{
|
||||||
internal interface IAsyncIOEngine: IDisposable
|
internal interface IAsyncIOEngine: IDisposable
|
||||||
{
|
{
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
||||||
{
|
{
|
||||||
internal partial class WebSocketsAsyncIOEngine
|
internal partial class WebSocketsAsyncIOEngine
|
||||||
{
|
{
|
||||||
|
|
@ -5,7 +5,7 @@ using System;
|
||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
||||||
{
|
{
|
||||||
internal partial class WebSocketsAsyncIOEngine
|
internal partial class WebSocketsAsyncIOEngine
|
||||||
{
|
{
|
||||||
|
|
@ -5,7 +5,7 @@ using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.AspNetCore.HttpSys.Internal;
|
using Microsoft.AspNetCore.HttpSys.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
||||||
{
|
{
|
||||||
internal partial class WebSocketsAsyncIOEngine
|
internal partial class WebSocketsAsyncIOEngine
|
||||||
{
|
{
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Buffers;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core.IO
|
||||||
{
|
{
|
||||||
internal partial class WebSocketsAsyncIOEngine: IAsyncIOEngine
|
internal partial class WebSocketsAsyncIOEngine: IAsyncIOEngine
|
||||||
{
|
{
|
||||||
|
|
@ -7,7 +7,7 @@ using System.IO.Pipelines;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
{
|
{
|
||||||
internal class OutputProducer
|
internal class OutputProducer
|
||||||
{
|
{
|
||||||
|
|
@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.IIS
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extensions to <see cref="HttpContext"/> that enable access to IIS features.
|
/// Extensions to <see cref="HttpContext"/> that enable access to IIS features.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class IISHttpContextExtensions
|
public static class HttpContextExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the value of a server variable for the current request.
|
/// Gets the value of a server variable for the current request.
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Server.IIS
|
||||||
|
{
|
||||||
|
public class IISServerDefaults
|
||||||
|
{
|
||||||
|
public static readonly string AuthenticationScheme = "Windows";
|
||||||
|
public const string Negotiate = "Negotiate";
|
||||||
|
public const string Ntlm = "NTLM";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Builder
|
||||||
|
{
|
||||||
|
public class IISServerOptions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// If true the server should set HttpContext.User. If false the server will only provide an
|
||||||
|
/// identity when explicitly requested by the AuthenticationScheme.
|
||||||
|
/// Note Windows Authentication must also be enabled in IIS for this to work.
|
||||||
|
/// </summary>
|
||||||
|
public bool AutomaticAuthentication { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the display name shown to users on login pages. The default is null.
|
||||||
|
/// </summary>
|
||||||
|
public string AuthenticationDisplayName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to indicate if the authentication handler should be registered. This is only done if ANCM indicates
|
||||||
|
/// IIS has a non-anonymous authentication enabled, or for back compat with ANCMs that did not provide this information.
|
||||||
|
/// </summary>
|
||||||
|
internal bool ForwardWindowsAuthentication { get; set; } = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,56 +1,36 @@
|
||||||
<Project>
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
|
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<PackageId>Microsoft.AspNetCore.Server.IIS</PackageId>
|
<PackageId>Microsoft.AspNetCore.Server.IIS</PackageId>
|
||||||
<Description>Provides support for hosting ASP.NET Core in IIS using the AspNetCoreModule.</Description>
|
<Description>Provides support for hosting ASP.NET Core in IIS using the AspNetCoreModule.</Description>
|
||||||
<IsPackable Condition="'$(OS)' != 'Windows_NT'">false</IsPackable>
|
<IsPackable Condition="'$(OS)' != 'Windows_NT'">false</IsPackable>
|
||||||
<IncludeSource>false</IncludeSource>
|
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||||
<IncludeSymbols>false</IncludeSymbols>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<IncludeBuildOutput>false</IncludeBuildOutput>
|
<PackageTags>aspnetcore;iis</PackageTags>
|
||||||
<EnableApiCheck>false</EnableApiCheck>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<NoPackageAnalysis>true</NoPackageAnalysis>
|
|
||||||
<NuspecFile>$(PackageId).nuspec</NuspecFile>
|
|
||||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<SignedPackageFile Include="$(TargetPath)" PackagePath="lib/netstandard2.0/Microsoft.AspNetCore.Server.IIS.dll" Certificate="Microsoft" />
|
||||||
<SignedPackageFile Include="aspnetcorerh_x86" PackagePath="runtimes/win-x86/nativeassets/$(TargetFramework)/aspnetcorerh.dll" Certificate="Microsoft" />
|
<SignedPackageFile Include="aspnetcorerh_x86" PackagePath="runtimes/win-x86/nativeassets/$(TargetFramework)/aspnetcorerh.dll" Certificate="Microsoft" />
|
||||||
<SignedPackageFile Include="aspnetcorerh_x64" PackagePath="runtimes/win-x64/nativeassets/$(TargetFramework)/aspnetcorerh.dll" Certificate="Microsoft" />
|
<SignedPackageFile Include="aspnetcorerh_x64" PackagePath="runtimes/win-x64/nativeassets/$(TargetFramework)/aspnetcorerh.dll" Certificate="Microsoft" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" />
|
<PackageReference Include="Microsoft.AspNetCore.HttpSys.Sources" PrivateAssets="All" Version="$(MicrosoftAspNetCoreHttpSysSourcesPackageVersion)" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Buffers.Sources" Version="$(MicrosoftExtensionsBuffersSourcesPackageVersion)" PrivateAssets="All" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Buffers.MemoryPool.Sources" Version="$(MicrosoftExtensionsBuffersMemoryPoolSourcesPackageVersion)" PrivateAssets="All" />
|
||||||
|
|
||||||
|
<PackageReference Include="System.IO.Pipelines" Version="$(SystemIOPipelinesPackageVersion)" />
|
||||||
|
<PackageReference Include="System.Security.Principal.Windows" Version="$(SystemSecurityPrincipalWindowsPackageVersion)" />
|
||||||
|
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.Core" Version="$(MicrosoftAspNetCoreAuthenticationCorePackageVersion)" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="$(MicrosoftAspNetCoreHostingAbstractionsPackageVersion)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="SetPackageProperties" BeforeTargets="GenerateNuspec">
|
<ItemGroup>
|
||||||
<PropertyGroup>
|
<Content Include="..\AspNetCoreModuleV2\RequestHandler\bin\$(Configuration)\Win32\aspnetcorerh.dll" PackagePath="runtimes/win-x86/nativeassets/$(TargetFramework)/aspnetcorerh.dll" />
|
||||||
<NuspecProperties>
|
<Content Include="..\AspNetCoreModuleV2\RequestHandler\bin\$(Configuration)\x64\aspnetcorerh.dll" PackagePath="runtimes/win-x64/nativeassets/$(TargetFramework)/aspnetcorerh.dll" />
|
||||||
id=$(PackageId);
|
</ItemGroup>
|
||||||
tfm=$(TargetFramework);
|
|
||||||
tfmGroup=$(TargetFrameworkIdentifier)$(_TargetFrameworkVersionWithoutV);
|
|
||||||
configuration=$(Configuration);
|
|
||||||
copyright=$(Copyright);
|
|
||||||
author=$(Authors);
|
|
||||||
licenseUrl=$(PackageLicenseUrl);
|
|
||||||
iconUrl=$(PackageIconUrl);
|
|
||||||
projectUrl=$(PackageProjectUrl);
|
|
||||||
repositoryUrl=$(RepositoryUrl);
|
|
||||||
repositoryType=$(RepositoryType);
|
|
||||||
repositoryCommit=$(RepositoryCommit);
|
|
||||||
version=$(PackageVersion);
|
|
||||||
description=$(Description);
|
|
||||||
serviceable=$([MSBuild]::ValueOrDefault('$(Serviceable)', 'false'));
|
|
||||||
</NuspecProperties>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Target>
|
|
||||||
|
|
||||||
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
|
|
||||||
|
|
||||||
<!-- This project doesn't actually compile anything. It's a shim into packing a nuspec -->
|
|
||||||
<Target Name="Compile" />
|
|
||||||
<Target Name="CopyFilesToOutputDirectory" />
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,274 @@
|
||||||
|
// 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.Runtime.InteropServices;
|
||||||
|
using Microsoft.AspNetCore.HttpSys.Internal;
|
||||||
|
using Microsoft.AspNetCore.Server.IIS.Core;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Server.IIS
|
||||||
|
{
|
||||||
|
internal static class NativeMethods
|
||||||
|
{
|
||||||
|
internal const int HR_OK = 0;
|
||||||
|
internal const int ERROR_NOT_FOUND = unchecked((int)0x80070490);
|
||||||
|
internal const int ERROR_OPERATION_ABORTED = unchecked((int)0x800703E3);
|
||||||
|
|
||||||
|
private const string KERNEL32 = "kernel32.dll";
|
||||||
|
|
||||||
|
private const string AspNetCoreModuleDll = "aspnetcorerh.dll";
|
||||||
|
|
||||||
|
[DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)]
|
||||||
|
|
||||||
|
public static extern bool CloseHandle(IntPtr handle);
|
||||||
|
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll")]
|
||||||
|
private static extern IntPtr GetModuleHandle(string lpModuleName);
|
||||||
|
|
||||||
|
public static bool IsAspNetCoreModuleLoaded()
|
||||||
|
{
|
||||||
|
return GetModuleHandle(AspNetCoreModuleDll) != IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum REQUEST_NOTIFICATION_STATUS
|
||||||
|
{
|
||||||
|
RQ_NOTIFICATION_CONTINUE,
|
||||||
|
RQ_NOTIFICATION_PENDING,
|
||||||
|
RQ_NOTIFICATION_FINISH_REQUEST
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate REQUEST_NOTIFICATION_STATUS PFN_REQUEST_HANDLER(IntPtr pInProcessHandler, IntPtr pvRequestContext);
|
||||||
|
public delegate bool PFN_SHUTDOWN_HANDLER(IntPtr pvRequestContext);
|
||||||
|
public delegate REQUEST_NOTIFICATION_STATUS PFN_ASYNC_COMPLETION(IntPtr pvManagedHttpContext, int hr, int bytes);
|
||||||
|
public delegate REQUEST_NOTIFICATION_STATUS PFN_WEBSOCKET_ASYNC_COMPLETION(IntPtr pInProcessHandler, IntPtr completionInfo, IntPtr pvCompletionContext);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern int http_post_completion(IntPtr pInProcessHandler, int cbBytes);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern int http_set_completion_status(IntPtr pInProcessHandler, REQUEST_NOTIFICATION_STATUS rquestNotificationStatus);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern void http_indicate_completion(IntPtr pInProcessHandler, REQUEST_NOTIFICATION_STATUS notificationStatus);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern void register_callbacks(PFN_REQUEST_HANDLER request_callback, PFN_SHUTDOWN_HANDLER shutdown_callback, PFN_ASYNC_COMPLETION managed_context_handler, IntPtr pvRequestContext, IntPtr pvShutdownContext);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern unsafe int http_write_response_bytes(IntPtr pInProcessHandler, HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks, int nChunks, out bool fCompletionExpected);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern int http_flush_response_bytes(IntPtr pInProcessHandler, out bool fCompletionExpected);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern unsafe HttpApiTypes.HTTP_REQUEST_V2* http_get_raw_request(IntPtr pInProcessHandler);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern void http_stop_calls_into_managed();
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern void http_stop_incoming_requests();
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern unsafe HttpApiTypes.HTTP_RESPONSE_V2* http_get_raw_response(IntPtr pInProcessHandler);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll, CharSet = CharSet.Ansi)]
|
||||||
|
private static extern int http_set_response_status_code(IntPtr pInProcessHandler, ushort statusCode, string pszReason);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern unsafe int http_read_request_bytes(IntPtr pInProcessHandler, byte* pvBuffer, int cbBuffer, out int dwBytesReceived, out bool fCompletionExpected);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern void http_get_completion_info(IntPtr pCompletionInfo, out int cbBytes, out int hr);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern int http_set_managed_context(IntPtr pInProcessHandler, IntPtr pvManagedContext);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern int http_get_application_properties(ref IISConfigurationData iiConfigData);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern int http_get_server_variable(
|
||||||
|
IntPtr pInProcessHandler,
|
||||||
|
[MarshalAs(UnmanagedType.LPStr)] string variableName,
|
||||||
|
[MarshalAs(UnmanagedType.BStr)] out string value);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern unsafe int http_websockets_read_bytes(
|
||||||
|
IntPtr pInProcessHandler,
|
||||||
|
byte* pvBuffer,
|
||||||
|
int cbBuffer,
|
||||||
|
PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback,
|
||||||
|
IntPtr pvCompletionContext,
|
||||||
|
out int dwBytesReceived,
|
||||||
|
out bool fCompletionExpected);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern unsafe int http_websockets_write_bytes(
|
||||||
|
IntPtr pInProcessHandler,
|
||||||
|
HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks,
|
||||||
|
int nChunks,
|
||||||
|
PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback,
|
||||||
|
IntPtr pvCompletionContext,
|
||||||
|
out bool fCompletionExpected);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern int http_enable_websockets(IntPtr pInProcessHandler);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern int http_cancel_io(IntPtr pInProcessHandler);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern unsafe int http_response_set_unknown_header(IntPtr pInProcessHandler, byte* pszHeaderName, byte* pszHeaderValue, ushort usHeaderValueLength, bool fReplace);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern unsafe int http_response_set_known_header(IntPtr pInProcessHandler, int headerId, byte* pHeaderValue, ushort length, bool fReplace);
|
||||||
|
|
||||||
|
[DllImport(AspNetCoreModuleDll)]
|
||||||
|
private static extern int http_get_authentication_information(IntPtr pInProcessHandler, [MarshalAs(UnmanagedType.BStr)] out string authType, out IntPtr token);
|
||||||
|
|
||||||
|
public static void HttpPostCompletion(IntPtr pInProcessHandler, int cbBytes)
|
||||||
|
{
|
||||||
|
Validate(http_post_completion(pInProcessHandler, cbBytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void HttpSetCompletionStatus(IntPtr pInProcessHandler, REQUEST_NOTIFICATION_STATUS rquestNotificationStatus)
|
||||||
|
{
|
||||||
|
Validate(http_set_completion_status(pInProcessHandler, rquestNotificationStatus));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void HttpIndicateCompletion(IntPtr pInProcessHandler, REQUEST_NOTIFICATION_STATUS notificationStatus)
|
||||||
|
{
|
||||||
|
http_indicate_completion(pInProcessHandler, notificationStatus);
|
||||||
|
}
|
||||||
|
public static void HttpRegisterCallbacks(PFN_REQUEST_HANDLER request_callback, PFN_SHUTDOWN_HANDLER shutdown_callback, PFN_ASYNC_COMPLETION managed_context_handler, IntPtr pvRequestContext, IntPtr pvShutdownContext)
|
||||||
|
{
|
||||||
|
register_callbacks(request_callback, shutdown_callback, managed_context_handler, pvRequestContext, pvShutdownContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe int HttpWriteResponseBytes(IntPtr pInProcessHandler, HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks, int nChunks, out bool fCompletionExpected)
|
||||||
|
{
|
||||||
|
return http_write_response_bytes(pInProcessHandler, pDataChunks, nChunks, out fCompletionExpected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int HttpFlushResponseBytes(IntPtr pInProcessHandler, out bool fCompletionExpected)
|
||||||
|
{
|
||||||
|
return http_flush_response_bytes(pInProcessHandler, out fCompletionExpected);
|
||||||
|
}
|
||||||
|
public static unsafe HttpApiTypes.HTTP_REQUEST_V2* HttpGetRawRequest(IntPtr pInProcessHandler)
|
||||||
|
{
|
||||||
|
return http_get_raw_request(pInProcessHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void HttpStopCallsIntoManaged()
|
||||||
|
{
|
||||||
|
http_stop_calls_into_managed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void HttpStopIncomingRequests()
|
||||||
|
{
|
||||||
|
http_stop_incoming_requests();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe HttpApiTypes.HTTP_RESPONSE_V2* HttpGetRawResponse(IntPtr pInProcessHandler)
|
||||||
|
{
|
||||||
|
return http_get_raw_response(pInProcessHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void HttpSetResponseStatusCode(IntPtr pInProcessHandler, ushort statusCode, string pszReason)
|
||||||
|
{
|
||||||
|
Validate(http_set_response_status_code(pInProcessHandler, statusCode, pszReason));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe int HttpReadRequestBytes(IntPtr pInProcessHandler, byte* pvBuffer, int cbBuffer, out int dwBytesReceived, out bool fCompletionExpected)
|
||||||
|
{
|
||||||
|
return http_read_request_bytes(pInProcessHandler, pvBuffer, cbBuffer, out dwBytesReceived, out fCompletionExpected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void HttpGetCompletionInfo(IntPtr pCompletionInfo, out int cbBytes, out int hr)
|
||||||
|
{
|
||||||
|
http_get_completion_info(pCompletionInfo, out cbBytes, out hr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void HttpSetManagedContext(IntPtr pInProcessHandler, IntPtr pvManagedContext)
|
||||||
|
{
|
||||||
|
Validate(http_set_managed_context(pInProcessHandler, pvManagedContext));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IISConfigurationData HttpGetApplicationProperties()
|
||||||
|
{
|
||||||
|
var iisConfigurationData = new IISConfigurationData();
|
||||||
|
Validate(http_get_application_properties(ref iisConfigurationData));
|
||||||
|
return iisConfigurationData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool HttpTryGetServerVariable(IntPtr pInProcessHandler, string variableName, out string value)
|
||||||
|
{
|
||||||
|
return http_get_server_variable(pInProcessHandler, variableName, out value) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe int HttpWebsocketsReadBytes(
|
||||||
|
IntPtr pInProcessHandler,
|
||||||
|
byte* pvBuffer,
|
||||||
|
int cbBuffer,
|
||||||
|
PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback,
|
||||||
|
IntPtr pvCompletionContext, out int dwBytesReceived,
|
||||||
|
out bool fCompletionExpected)
|
||||||
|
{
|
||||||
|
return http_websockets_read_bytes(pInProcessHandler, pvBuffer, cbBuffer, pfnCompletionCallback, pvCompletionContext, out dwBytesReceived, out fCompletionExpected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe int HttpWebsocketsWriteBytes(
|
||||||
|
IntPtr pInProcessHandler,
|
||||||
|
HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks,
|
||||||
|
int nChunks,
|
||||||
|
PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback,
|
||||||
|
IntPtr pvCompletionContext,
|
||||||
|
out bool fCompletionExpected)
|
||||||
|
{
|
||||||
|
return http_websockets_write_bytes(pInProcessHandler, pDataChunks, nChunks, pfnCompletionCallback, pvCompletionContext, out fCompletionExpected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void HttpEnableWebsockets(IntPtr pInProcessHandler)
|
||||||
|
{
|
||||||
|
Validate(http_enable_websockets(pInProcessHandler));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool HttpTryCancelIO(IntPtr pInProcessHandler)
|
||||||
|
{
|
||||||
|
var hr = http_cancel_io(pInProcessHandler);
|
||||||
|
// Async operation finished
|
||||||
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363792(v=vs.85).aspx
|
||||||
|
if (hr == ERROR_NOT_FOUND)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Validate(hr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe void HttpResponseSetUnknownHeader(IntPtr pInProcessHandler, byte* pszHeaderName, byte* pszHeaderValue, ushort usHeaderValueLength, bool fReplace)
|
||||||
|
{
|
||||||
|
Validate(http_response_set_unknown_header(pInProcessHandler, pszHeaderName, pszHeaderValue, usHeaderValueLength, fReplace));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe void HttpResponseSetKnownHeader(IntPtr pInProcessHandler, int headerId, byte* pHeaderValue, ushort length, bool fReplace)
|
||||||
|
{
|
||||||
|
Validate(http_response_set_known_header(pInProcessHandler, headerId, pHeaderValue, length, fReplace));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void HttpGetAuthenticationInformation(IntPtr pInProcessHandler, out string authType, out IntPtr token)
|
||||||
|
{
|
||||||
|
Validate(http_get_authentication_information(pInProcessHandler, out authType, out token));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Validate(int hr)
|
||||||
|
{
|
||||||
|
if (hr != HR_OK)
|
||||||
|
{
|
||||||
|
throw Marshal.GetExceptionForHR(hr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
// 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.Runtime.InteropServices;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.AspNetCore.Hosting.Server;
|
||||||
|
using Microsoft.AspNetCore.Server.IIS;
|
||||||
|
using Microsoft.AspNetCore.Server.IIS.Core;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Hosting
|
||||||
|
{
|
||||||
|
public static class WebHostBuilderIISExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Configures the port and base path the server should listen on when running behind AspNetCoreModule.
|
||||||
|
/// The app will also be configured to capture startup errors.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hostBuilder"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IWebHostBuilder UseIIS(this IWebHostBuilder hostBuilder)
|
||||||
|
{
|
||||||
|
if (hostBuilder == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(hostBuilder));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if in process
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && NativeMethods.IsAspNetCoreModuleLoaded())
|
||||||
|
{
|
||||||
|
hostBuilder.CaptureStartupErrors(true);
|
||||||
|
|
||||||
|
var iisConfigData = NativeMethods.HttpGetApplicationProperties();
|
||||||
|
hostBuilder.UseContentRoot(iisConfigData.pwzFullApplicationPath);
|
||||||
|
return hostBuilder.ConfigureServices(
|
||||||
|
services => {
|
||||||
|
services.AddSingleton<IServer, IISHttpServer>();
|
||||||
|
services.AddSingleton<IStartupFilter>(new IISServerSetupFilter(iisConfigData.pwzVirtualApplicationPath));
|
||||||
|
services.AddAuthenticationCore();
|
||||||
|
services.Configure<IISServerOptions>(
|
||||||
|
options => { options.ForwardWindowsAuthentication = iisConfigData.fWindowsAuthEnabled || iisConfigData.fBasicAuthEnabled; }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return hostBuilder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>ASP.NET Core components for working with the IIS AspNetCoreModule.</Description>
|
<Description>ASP.NET Core components for working with the IIS AspNetCoreModule.</Description>
|
||||||
|
|
@ -21,9 +21,6 @@
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="$(MicrosoftAspNetCoreHttpPackageVersion)" />
|
<PackageReference Include="Microsoft.AspNetCore.Http" Version="$(MicrosoftAspNetCoreHttpPackageVersion)" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="$(MicrosoftAspNetCoreHttpExtensionsPackageVersion)" />
|
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="$(MicrosoftAspNetCoreHttpExtensionsPackageVersion)" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.HttpOverrides" Version="$(MicrosoftAspNetCoreHttpOverridesPackageVersion)" />
|
<PackageReference Include="Microsoft.AspNetCore.HttpOverrides" Version="$(MicrosoftAspNetCoreHttpOverridesPackageVersion)" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.HttpSys.Sources" PrivateAssets="All" Version="$(MicrosoftAspNetCoreHttpSysSourcesPackageVersion)" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Buffers.Sources" Version="$(MicrosoftExtensionsBuffersSourcesPackageVersion)" PrivateAssets="All" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Buffers.MemoryPool.Sources" Version="$(MicrosoftExtensionsBuffersMemoryPoolSourcesPackageVersion)" PrivateAssets="All" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsLoggingAbstractionsPackageVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsLoggingAbstractionsPackageVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionsOptionsPackageVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionsOptionsPackageVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.SecurityHelper.Sources" PrivateAssets="All" Version="$(MicrosoftExtensionsSecurityHelperSourcesPackageVersion)" />
|
<PackageReference Include="Microsoft.Extensions.SecurityHelper.Sources" PrivateAssets="All" Version="$(MicrosoftExtensionsSecurityHelperSourcesPackageVersion)" />
|
||||||
|
|
|
||||||
|
|
@ -3,271 +3,15 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.AspNetCore.HttpSys.Internal;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration
|
namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||||
{
|
{
|
||||||
internal static class NativeMethods
|
internal static class NativeMethods
|
||||||
{
|
{
|
||||||
internal const int HR_OK = 0;
|
|
||||||
internal const int ERROR_NOT_FOUND = unchecked((int)0x80070490);
|
|
||||||
internal const int ERROR_OPERATION_ABORTED = unchecked((int)0x800703E3);
|
|
||||||
|
|
||||||
private const string KERNEL32 = "kernel32.dll";
|
private const string KERNEL32 = "kernel32.dll";
|
||||||
|
|
||||||
private const string AspNetCoreModuleDll = "aspnetcorerh.dll";
|
|
||||||
|
|
||||||
[DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)]
|
[DllImport(KERNEL32, ExactSpelling = true, SetLastError = true)]
|
||||||
|
|
||||||
public static extern bool CloseHandle(IntPtr handle);
|
public static extern bool CloseHandle(IntPtr handle);
|
||||||
|
|
||||||
|
|
||||||
[DllImport("kernel32.dll")]
|
|
||||||
private static extern IntPtr GetModuleHandle(string lpModuleName);
|
|
||||||
|
|
||||||
public static bool IsAspNetCoreModuleLoaded()
|
|
||||||
{
|
|
||||||
return GetModuleHandle(AspNetCoreModuleDll) != IntPtr.Zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum REQUEST_NOTIFICATION_STATUS
|
|
||||||
{
|
|
||||||
RQ_NOTIFICATION_CONTINUE,
|
|
||||||
RQ_NOTIFICATION_PENDING,
|
|
||||||
RQ_NOTIFICATION_FINISH_REQUEST
|
|
||||||
}
|
|
||||||
|
|
||||||
public delegate REQUEST_NOTIFICATION_STATUS PFN_REQUEST_HANDLER(IntPtr pInProcessHandler, IntPtr pvRequestContext);
|
|
||||||
public delegate bool PFN_SHUTDOWN_HANDLER(IntPtr pvRequestContext);
|
|
||||||
public delegate REQUEST_NOTIFICATION_STATUS PFN_ASYNC_COMPLETION(IntPtr pvManagedHttpContext, int hr, int bytes);
|
|
||||||
public delegate REQUEST_NOTIFICATION_STATUS PFN_WEBSOCKET_ASYNC_COMPLETION(IntPtr pInProcessHandler, IntPtr completionInfo, IntPtr pvCompletionContext);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern int http_post_completion(IntPtr pInProcessHandler, int cbBytes);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern int http_set_completion_status(IntPtr pInProcessHandler, REQUEST_NOTIFICATION_STATUS rquestNotificationStatus);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern void http_indicate_completion(IntPtr pInProcessHandler, REQUEST_NOTIFICATION_STATUS notificationStatus);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern void register_callbacks(PFN_REQUEST_HANDLER request_callback, PFN_SHUTDOWN_HANDLER shutdown_callback, PFN_ASYNC_COMPLETION managed_context_handler, IntPtr pvRequestContext, IntPtr pvShutdownContext);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern unsafe int http_write_response_bytes(IntPtr pInProcessHandler, HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks, int nChunks, out bool fCompletionExpected);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern int http_flush_response_bytes(IntPtr pInProcessHandler, out bool fCompletionExpected);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern unsafe HttpApiTypes.HTTP_REQUEST_V2* http_get_raw_request(IntPtr pInProcessHandler);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern void http_stop_calls_into_managed();
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern void http_stop_incoming_requests();
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern unsafe HttpApiTypes.HTTP_RESPONSE_V2* http_get_raw_response(IntPtr pInProcessHandler);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll, CharSet = CharSet.Ansi)]
|
|
||||||
private static extern int http_set_response_status_code(IntPtr pInProcessHandler, ushort statusCode, string pszReason);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern unsafe int http_read_request_bytes(IntPtr pInProcessHandler, byte* pvBuffer, int cbBuffer, out int dwBytesReceived, out bool fCompletionExpected);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern void http_get_completion_info(IntPtr pCompletionInfo, out int cbBytes, out int hr);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern int http_set_managed_context(IntPtr pInProcessHandler, IntPtr pvManagedContext);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern int http_get_application_properties(ref IISConfigurationData iiConfigData);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern int http_get_server_variable(
|
|
||||||
IntPtr pInProcessHandler,
|
|
||||||
[MarshalAs(UnmanagedType.LPStr)] string variableName,
|
|
||||||
[MarshalAs(UnmanagedType.BStr)] out string value);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern unsafe int http_websockets_read_bytes(
|
|
||||||
IntPtr pInProcessHandler,
|
|
||||||
byte* pvBuffer,
|
|
||||||
int cbBuffer,
|
|
||||||
PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback,
|
|
||||||
IntPtr pvCompletionContext,
|
|
||||||
out int dwBytesReceived,
|
|
||||||
out bool fCompletionExpected);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern unsafe int http_websockets_write_bytes(
|
|
||||||
IntPtr pInProcessHandler,
|
|
||||||
HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks,
|
|
||||||
int nChunks,
|
|
||||||
PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback,
|
|
||||||
IntPtr pvCompletionContext,
|
|
||||||
out bool fCompletionExpected);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern int http_enable_websockets(IntPtr pInProcessHandler);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern int http_cancel_io(IntPtr pInProcessHandler);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern unsafe int http_response_set_unknown_header(IntPtr pInProcessHandler, byte* pszHeaderName, byte* pszHeaderValue, ushort usHeaderValueLength, bool fReplace);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern unsafe int http_response_set_known_header(IntPtr pInProcessHandler, int headerId, byte* pHeaderValue, ushort length, bool fReplace);
|
|
||||||
|
|
||||||
[DllImport(AspNetCoreModuleDll)]
|
|
||||||
private static extern int http_get_authentication_information(IntPtr pInProcessHandler, [MarshalAs(UnmanagedType.BStr)] out string authType, out IntPtr token);
|
|
||||||
|
|
||||||
public static void HttpPostCompletion(IntPtr pInProcessHandler, int cbBytes)
|
|
||||||
{
|
|
||||||
Validate(http_post_completion(pInProcessHandler, cbBytes));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void HttpSetCompletionStatus(IntPtr pInProcessHandler, REQUEST_NOTIFICATION_STATUS rquestNotificationStatus)
|
|
||||||
{
|
|
||||||
Validate(http_set_completion_status(pInProcessHandler, rquestNotificationStatus));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void HttpIndicateCompletion(IntPtr pInProcessHandler, REQUEST_NOTIFICATION_STATUS notificationStatus)
|
|
||||||
{
|
|
||||||
http_indicate_completion(pInProcessHandler, notificationStatus);
|
|
||||||
}
|
|
||||||
public static void HttpRegisterCallbacks(PFN_REQUEST_HANDLER request_callback, PFN_SHUTDOWN_HANDLER shutdown_callback, PFN_ASYNC_COMPLETION managed_context_handler, IntPtr pvRequestContext, IntPtr pvShutdownContext)
|
|
||||||
{
|
|
||||||
register_callbacks(request_callback, shutdown_callback, managed_context_handler, pvRequestContext, pvShutdownContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static unsafe int HttpWriteResponseBytes(IntPtr pInProcessHandler, HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks, int nChunks, out bool fCompletionExpected)
|
|
||||||
{
|
|
||||||
return http_write_response_bytes(pInProcessHandler, pDataChunks, nChunks, out fCompletionExpected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int HttpFlushResponseBytes(IntPtr pInProcessHandler, out bool fCompletionExpected)
|
|
||||||
{
|
|
||||||
return http_flush_response_bytes(pInProcessHandler, out fCompletionExpected);
|
|
||||||
}
|
|
||||||
public static unsafe HttpApiTypes.HTTP_REQUEST_V2* HttpGetRawRequest(IntPtr pInProcessHandler)
|
|
||||||
{
|
|
||||||
return http_get_raw_request(pInProcessHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void HttpStopCallsIntoManaged()
|
|
||||||
{
|
|
||||||
http_stop_calls_into_managed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void HttpStopIncomingRequests()
|
|
||||||
{
|
|
||||||
http_stop_incoming_requests();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static unsafe HttpApiTypes.HTTP_RESPONSE_V2* HttpGetRawResponse(IntPtr pInProcessHandler)
|
|
||||||
{
|
|
||||||
return http_get_raw_response(pInProcessHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void HttpSetResponseStatusCode(IntPtr pInProcessHandler, ushort statusCode, string pszReason)
|
|
||||||
{
|
|
||||||
Validate(http_set_response_status_code(pInProcessHandler, statusCode, pszReason));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static unsafe int HttpReadRequestBytes(IntPtr pInProcessHandler, byte* pvBuffer, int cbBuffer, out int dwBytesReceived, out bool fCompletionExpected)
|
|
||||||
{
|
|
||||||
return http_read_request_bytes(pInProcessHandler, pvBuffer, cbBuffer, out dwBytesReceived, out fCompletionExpected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void HttpGetCompletionInfo(IntPtr pCompletionInfo, out int cbBytes, out int hr)
|
|
||||||
{
|
|
||||||
http_get_completion_info(pCompletionInfo, out cbBytes, out hr);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void HttpSetManagedContext(IntPtr pInProcessHandler, IntPtr pvManagedContext)
|
|
||||||
{
|
|
||||||
Validate(http_set_managed_context(pInProcessHandler, pvManagedContext));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IISConfigurationData HttpGetApplicationProperties()
|
|
||||||
{
|
|
||||||
var iisConfigurationData = new IISConfigurationData();
|
|
||||||
Validate(http_get_application_properties(ref iisConfigurationData));
|
|
||||||
return iisConfigurationData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool HttpTryGetServerVariable(IntPtr pInProcessHandler, string variableName, out string value)
|
|
||||||
{
|
|
||||||
return http_get_server_variable(pInProcessHandler, variableName, out value) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static unsafe int HttpWebsocketsReadBytes(
|
|
||||||
IntPtr pInProcessHandler,
|
|
||||||
byte* pvBuffer,
|
|
||||||
int cbBuffer,
|
|
||||||
PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback,
|
|
||||||
IntPtr pvCompletionContext, out int dwBytesReceived,
|
|
||||||
out bool fCompletionExpected)
|
|
||||||
{
|
|
||||||
return http_websockets_read_bytes(pInProcessHandler, pvBuffer, cbBuffer, pfnCompletionCallback, pvCompletionContext, out dwBytesReceived, out fCompletionExpected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static unsafe int HttpWebsocketsWriteBytes(
|
|
||||||
IntPtr pInProcessHandler,
|
|
||||||
HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks,
|
|
||||||
int nChunks,
|
|
||||||
PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback,
|
|
||||||
IntPtr pvCompletionContext,
|
|
||||||
out bool fCompletionExpected)
|
|
||||||
{
|
|
||||||
return http_websockets_write_bytes(pInProcessHandler, pDataChunks, nChunks, pfnCompletionCallback, pvCompletionContext, out fCompletionExpected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void HttpEnableWebsockets(IntPtr pInProcessHandler)
|
|
||||||
{
|
|
||||||
Validate(http_enable_websockets(pInProcessHandler));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool HttpTryCancelIO(IntPtr pInProcessHandler)
|
|
||||||
{
|
|
||||||
var hr = http_cancel_io(pInProcessHandler);
|
|
||||||
// Async operation finished
|
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363792(v=vs.85).aspx
|
|
||||||
if (hr == ERROR_NOT_FOUND)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Validate(hr);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static unsafe void HttpResponseSetUnknownHeader(IntPtr pInProcessHandler, byte* pszHeaderName, byte* pszHeaderValue, ushort usHeaderValueLength, bool fReplace)
|
|
||||||
{
|
|
||||||
Validate(http_response_set_unknown_header(pInProcessHandler, pszHeaderName, pszHeaderValue, usHeaderValueLength, fReplace));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static unsafe void HttpResponseSetKnownHeader(IntPtr pInProcessHandler, int headerId, byte* pHeaderValue, ushort length, bool fReplace)
|
|
||||||
{
|
|
||||||
Validate(http_response_set_known_header(pInProcessHandler, headerId, pHeaderValue, length, fReplace));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void HttpGetAuthenticationInformation(IntPtr pInProcessHandler, out string authType, out IntPtr token)
|
|
||||||
{
|
|
||||||
Validate(http_get_authentication_information(pInProcessHandler, out authType, out token));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void Validate(int hr)
|
|
||||||
{
|
|
||||||
if (hr != HR_OK)
|
|
||||||
{
|
|
||||||
throw Marshal.GetExceptionForHR(hr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,6 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
return hostBuilder;
|
return hostBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if in process
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && NativeMethods.IsAspNetCoreModuleLoaded())
|
|
||||||
{
|
|
||||||
|
|
||||||
return SetupInProcessServer(hostBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
var port = hostBuilder.GetSetting(ServerPort) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{ServerPort}");
|
var port = hostBuilder.GetSetting(ServerPort) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{ServerPort}");
|
||||||
var path = hostBuilder.GetSetting(ServerPath) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{ServerPath}");
|
var path = hostBuilder.GetSetting(ServerPath) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{ServerPath}");
|
||||||
var pairingToken = hostBuilder.GetSetting(PairingToken) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{PairingToken}");
|
var pairingToken = hostBuilder.GetSetting(PairingToken) ?? Environment.GetEnvironmentVariable($"ASPNETCORE_{PairingToken}");
|
||||||
|
|
@ -107,23 +100,5 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
|
|
||||||
return hostBuilder;
|
return hostBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IWebHostBuilder SetupInProcessServer(IWebHostBuilder hostBuilder)
|
|
||||||
{
|
|
||||||
hostBuilder.UseSetting(nameof(UseIISIntegration), "true");
|
|
||||||
hostBuilder.CaptureStartupErrors(true);
|
|
||||||
|
|
||||||
var iisConfigData = NativeMethods.HttpGetApplicationProperties();
|
|
||||||
hostBuilder.UseContentRoot(iisConfigData.pwzFullApplicationPath);
|
|
||||||
return hostBuilder.ConfigureServices(
|
|
||||||
services => {
|
|
||||||
services.AddSingleton<IServer, IISHttpServer>();
|
|
||||||
services.AddSingleton<IStartupFilter>(new IISServerSetupFilter(iisConfigData.pwzVirtualApplicationPath));
|
|
||||||
services.AddAuthenticationCore();
|
|
||||||
services.Configure<IISOptions>(
|
|
||||||
options => { options.ForwardWindowsAuthentication = iisConfigData.fWindowsAuthEnabled || iisConfigData.fBasicAuthEnabled; }
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
|
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
{
|
{
|
||||||
|
|
@ -16,6 +17,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
|
|
||||||
public IISTestSiteFixture()
|
public IISTestSiteFixture()
|
||||||
{
|
{
|
||||||
|
var logging = AssemblyTestLog.ForAssembly(typeof(IISTestSiteFixture).Assembly);
|
||||||
|
|
||||||
var deploymentParameters = new DeploymentParameters(Helpers.GetInProcessTestSitesPath(),
|
var deploymentParameters = new DeploymentParameters(Helpers.GetInProcessTestSitesPath(),
|
||||||
ServerType.IISExpress,
|
ServerType.IISExpress,
|
||||||
RuntimeFlavor.CoreClr,
|
RuntimeFlavor.CoreClr,
|
||||||
|
|
@ -25,10 +28,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
SiteName = "HttpTestSite",
|
SiteName = "HttpTestSite",
|
||||||
TargetFramework = "netcoreapp2.1",
|
TargetFramework = "netcoreapp2.1",
|
||||||
ApplicationType = ApplicationType.Portable,
|
ApplicationType = ApplicationType.Portable,
|
||||||
ANCMVersion = ANCMVersion.AspNetCoreModuleV2
|
ANCMVersion = ANCMVersion.AspNetCoreModuleV2,
|
||||||
};
|
};
|
||||||
|
|
||||||
_deployer = ApplicationDeployerFactory.Create(deploymentParameters, NullLoggerFactory.Instance);
|
_deployer = ApplicationDeployerFactory.Create(deploymentParameters, logging.CreateLoggerFactory(null, nameof(IISTestSiteFixture)));
|
||||||
DeploymentResult = _deployer.DeployAsync().Result;
|
DeploymentResult = _deployer.DeployAsync().Result;
|
||||||
Client = DeploymentResult.HttpClient;
|
Client = DeploymentResult.HttpClient;
|
||||||
BaseUri = DeploymentResult.ApplicationBaseUri;
|
BaseUri = DeploymentResult.ApplicationBaseUri;
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
<Import Project="..\..\..\build\testsite.props" />
|
<Import Project="..\..\..\build\testsite.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
|
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" />
|
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.Server.IIS\Microsoft.AspNetCore.Server.IIS.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace IISTestSite
|
||||||
factory.AddConsole();
|
factory.AddConsole();
|
||||||
factory.AddFilter("Console", level => level >= LogLevel.Information);
|
factory.AddFilter("Console", level => level >= LogLevel.Information);
|
||||||
})
|
})
|
||||||
.UseIISIntegration()
|
.UseIIS()
|
||||||
.UseStartup(typeof(Program).Assembly.FullName)
|
.UseStartup(typeof(Program).Assembly.FullName)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,24 +3,17 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using IISIntegration.FunctionalTests;
|
using IISIntegration.FunctionalTests;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.AspNetCore.Server.IIS;
|
|
||||||
using Microsoft.AspNetCore.Server.IISIntegration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Primitives;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace IISTestSite
|
namespace IISTestSite
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,16 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.WebSockets;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using IISIntegration.FunctionalTests;
|
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.AspNetCore.Server.IIS;
|
using Microsoft.AspNetCore.Server.IIS;
|
||||||
using Microsoft.AspNetCore.Server.IISIntegration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -46,7 +38,7 @@ namespace IISTestSite
|
||||||
app.Run(async ctx =>
|
app.Run(async ctx =>
|
||||||
{
|
{
|
||||||
var varName = ctx.Request.Query["q"];
|
var varName = ctx.Request.Query["q"];
|
||||||
await ctx.Response.WriteAsync($"{varName}: {ctx.GetIISServerVariable(varName) ?? "(null)"}");
|
await ctx.Response.WriteAsync($"{varName}: {HttpContextExtensions.GetIISServerVariable(ctx, varName) ?? "(null)"}");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,7 +60,7 @@ namespace IISTestSite
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await ctx.ChallengeAsync(IISDefaults.AuthenticationScheme);
|
await ctx.ChallengeAsync(IISServerDefaults.AuthenticationScheme);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +69,7 @@ namespace IISTestSite
|
||||||
{
|
{
|
||||||
app.Run(async ctx =>
|
app.Run(async ctx =>
|
||||||
{
|
{
|
||||||
await ctx.ForbidAsync(IISDefaults.AuthenticationScheme);
|
await ctx.ForbidAsync(IISServerDefaults.AuthenticationScheme);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,7 +83,7 @@ namespace IISTestSite
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await ctx.ChallengeAsync(IISDefaults.AuthenticationScheme);
|
await ctx.ChallengeAsync(IISServerDefaults.AuthenticationScheme);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
<Import Project="..\..\..\build\testsite.props" />
|
<Import Project="..\..\..\build\testsite.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
|
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" />
|
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.Server.IIS\Microsoft.AspNetCore.Server.IIS.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace IISTestSite
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var host = new WebHostBuilder()
|
var host = new WebHostBuilder()
|
||||||
.UseIISIntegration()
|
.UseIIS()
|
||||||
.ConfigureServices(services => services.AddSingleton<IServer, DummyServer>())
|
.ConfigureServices(services => services.AddSingleton<IServer, DummyServer>())
|
||||||
.Configure(builder => builder.Run(async context => { await context.Response.WriteAsync("I shouldn't work"); }))
|
.Configure(builder => builder.Run(async context => { await context.Response.WriteAsync("I shouldn't work"); }))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue