API docs for IIS (#26387)

This commit is contained in:
Justin Kotalik 2020-09-29 14:12:28 -07:00 committed by GitHub
parent 67ac1675c4
commit 75e707bc38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 105 additions and 6 deletions

View File

@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Server.IIS namespace Microsoft.AspNetCore.Server.IIS
{ {
///<inheritdoc/>
[Obsolete("Moved to Microsoft.AspNetCore.Http.BadHttpRequestException")] [Obsolete("Moved to Microsoft.AspNetCore.Http.BadHttpRequestException")]
public sealed class BadHttpRequestException : Microsoft.AspNetCore.Http.BadHttpRequestException public sealed class BadHttpRequestException : Microsoft.AspNetCore.Http.BadHttpRequestException
{ {
@ -17,6 +18,7 @@ namespace Microsoft.AspNetCore.Server.IIS
Reason = reason; Reason = reason;
} }
///<inheritdoc/>
public new int StatusCode { get => base.StatusCode; } public new int StatusCode { get => base.StatusCode; }
internal RequestRejectionReason Reason { get; } internal RequestRejectionReason Reason { get; }

View File

@ -8,6 +8,9 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Server.IIS.Core namespace Microsoft.AspNetCore.Server.IIS.Core
{ {
/// <summary>
/// The default authentication handler with IIS In-Process
/// </summary>
public class IISServerAuthenticationHandler : IAuthenticationHandler public class IISServerAuthenticationHandler : IAuthenticationHandler
{ {
private HttpContext _context; private HttpContext _context;
@ -15,6 +18,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
internal AuthenticationScheme Scheme { get; private set; } internal AuthenticationScheme Scheme { get; private set; }
///<inheritdoc/>
public Task<AuthenticateResult> AuthenticateAsync() public Task<AuthenticateResult> AuthenticateAsync()
{ {
var user = _iisHttpContext.WindowsUser; var user = _iisHttpContext.WindowsUser;
@ -28,6 +32,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
} }
} }
///<inheritdoc/>
public Task ChallengeAsync(AuthenticationProperties properties) public Task ChallengeAsync(AuthenticationProperties properties)
{ {
// We would normally set the www-authenticate header here, but IIS does that for us. // We would normally set the www-authenticate header here, but IIS does that for us.
@ -35,12 +40,14 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
return Task.CompletedTask; return Task.CompletedTask;
} }
///<inheritdoc/>
public Task ForbidAsync(AuthenticationProperties properties) public Task ForbidAsync(AuthenticationProperties properties)
{ {
_context.Response.StatusCode = 403; _context.Response.StatusCode = 403;
return Task.CompletedTask; return Task.CompletedTask;
} }
///<inheritdoc/>
public Task InitializeAsync(AuthenticationScheme scheme, HttpContext context) public Task InitializeAsync(AuthenticationScheme scheme, HttpContext context)
{ {
_iisHttpContext = context.Features.Get<IISHttpContext>(); _iisHttpContext = context.Features.Get<IISHttpContext>();

View File

@ -8,20 +8,31 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Server.IIS.Core namespace Microsoft.AspNetCore.Server.IIS.Core
{ {
/// <summary>
/// A <see cref="Stream"/> which throws on calls to write after the stream was upgraded
/// </summary>
/// <remarks>
/// Users should not need to instantiate this class.
/// </remarks>
public class ThrowingWasUpgradedWriteOnlyStream : WriteOnlyStream public class ThrowingWasUpgradedWriteOnlyStream : WriteOnlyStream
{ {
///<inheritdoc/>
public override void Write(byte[] buffer, int offset, int count) public override void Write(byte[] buffer, int offset, int count)
=> throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded); => throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded);
///<inheritdoc/>
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
=> throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded); => throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded);
///<inheritdoc/>
public override void Flush() public override void Flush()
=> throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded); => throw new InvalidOperationException(CoreStrings.ResponseStreamWasUpgraded);
///<inheritdoc/>
public override long Seek(long offset, SeekOrigin origin) public override long Seek(long offset, SeekOrigin origin)
=> throw new NotSupportedException(); => throw new NotSupportedException();
///<inheritdoc/>
public override void SetLength(long value) public override void SetLength(long value)
=> throw new NotSupportedException(); => throw new NotSupportedException();
} }

View File

@ -8,43 +8,56 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Server.IIS.Core namespace Microsoft.AspNetCore.Server.IIS.Core
{ {
/// <summary>
/// A <see cref="Stream"/> which only allows for writes.
/// </summary>
public abstract class WriteOnlyStream : Stream public abstract class WriteOnlyStream : Stream
{ {
///<inheritdoc/>
public override bool CanRead => false; public override bool CanRead => false;
///<inheritdoc/>
public override bool CanWrite => true; public override bool CanWrite => true;
///<inheritdoc/>
public override int ReadTimeout public override int ReadTimeout
{ {
get => throw new NotSupportedException(); get => throw new NotSupportedException();
set => throw new NotSupportedException(); set => throw new NotSupportedException();
} }
///<inheritdoc/>
public override bool CanSeek => false; public override bool CanSeek => false;
///<inheritdoc/>
public override long Length => throw new NotSupportedException(); public override long Length => throw new NotSupportedException();
///<inheritdoc/>
public override long Position public override long Position
{ {
get => throw new NotSupportedException(); get => throw new NotSupportedException();
set => throw new NotSupportedException(); set => throw new NotSupportedException();
} }
///<inheritdoc/>
public override int Read(byte[] buffer, int offset, int count) public override int Read(byte[] buffer, int offset, int count)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
///<inheritdoc/>
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
///<inheritdoc/>
public override long Seek(long offset, SeekOrigin origin) public override long Seek(long offset, SeekOrigin origin)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
///<inheritdoc/>
public override void SetLength(long value) public override void SetLength(long value)
{ {
throw new NotSupportedException(); throw new NotSupportedException();

View File

@ -3,8 +3,14 @@
namespace Microsoft.AspNetCore.Server.IIS namespace Microsoft.AspNetCore.Server.IIS
{ {
/// <summary>
/// String constants used to configure IIS In-Process.
/// </summary>
public class IISServerDefaults public class IISServerDefaults
{ {
/// <summary>
/// Default authentication scheme, which is "Windows".
/// </summary>
public const string AuthenticationScheme = "Windows"; public const string AuthenticationScheme = "Windows";
} }
} }

View File

@ -8,6 +8,9 @@ using Microsoft.AspNetCore.Server.IIS;
namespace Microsoft.AspNetCore.Builder namespace Microsoft.AspNetCore.Builder
{ {
/// <summary>
/// Provides configuration for IIS In-Process.
/// </summary>
public class IISServerOptions public class IISServerOptions
{ {
/// <summary> /// <summary>

View File

@ -5,7 +5,6 @@
<IsAspNetCoreApp>true</IsAspNetCoreApp> <IsAspNetCoreApp>true</IsAspNetCoreApp>
<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>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;iis</PackageTags> <PackageTags>aspnetcore;iis</PackageTags>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@ -13,6 +12,7 @@
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<!-- Ignore platform compatibility warnings for this project. We know this only works on windows.--> <!-- Ignore platform compatibility warnings for this project. We know this only works on windows.-->
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
<NoWarn>$(NoWarn);CA1416</NoWarn> <NoWarn>$(NoWarn);CA1416</NoWarn>
</PropertyGroup> </PropertyGroup>

View File

@ -12,14 +12,17 @@ using Microsoft.AspNetCore.Server.IIS.Core;
namespace Microsoft.AspNetCore.Hosting namespace Microsoft.AspNetCore.Hosting
{ {
/// <summary>
/// Extension methods for the IIS In-Process.
/// </summary>
public static class WebHostBuilderIISExtensions public static class WebHostBuilderIISExtensions
{ {
/// <summary> /// <summary>
/// Configures the port and base path the server should listen on when running behind AspNetCoreModule. /// 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. /// The app will also be configured to capture startup errors.
/// </summary> /// </summary>
/// <param name="hostBuilder"></param> /// <param name="hostBuilder">The <see cref="IWebHostBuilder"/> to configure.</param>
/// <returns></returns> /// <returns>The <see cref="IWebHostBuilder"/>.</returns>
public static IWebHostBuilder UseIIS(this IWebHostBuilder hostBuilder) public static IWebHostBuilder UseIIS(this IWebHostBuilder hostBuilder)
{ {
if (hostBuilder == null) if (hostBuilder == null)

View File

@ -3,10 +3,22 @@
namespace Microsoft.AspNetCore.Server.IISIntegration namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
/// <summary>
/// String constants used to configure IIS Out-Of-Process.
/// </summary>
public class IISDefaults public class IISDefaults
{ {
/// <summary>
/// Default authentication scheme, which is "Windows".
/// </summary>
public const string AuthenticationScheme = "Windows"; public const string AuthenticationScheme = "Windows";
/// <summary>
/// Default negotiate string, which is "Negotiate".
/// </summary>
public const string Negotiate = "Negotiate"; public const string Negotiate = "Negotiate";
/// <summary>
/// Default NTLM string, which is "NTLM".
/// </summary>
public const string Ntlm = "NTLM"; public const string Ntlm = "NTLM";
} }
} }

View File

@ -7,8 +7,18 @@ using Microsoft.AspNetCore.Hosting;
namespace Microsoft.AspNetCore.Server.IISIntegration namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
/// <summary>
/// The <see cref="IHostingStartup"/> to add IISIntegration to apps.
/// </summary>
/// <remarks>
/// This API isn't meant to be used by user code.
/// </remarks>
public class IISHostingStartup : IHostingStartup public class IISHostingStartup : IHostingStartup
{ {
/// <summary>
/// Adds IISIntegration into the middleware pipeline.
/// </summary>
/// <param name="builder">The <see cref="IWebHostBuilder"/>.</param>
public void Configure(IWebHostBuilder builder) public void Configure(IWebHostBuilder builder)
{ {
builder.UseIISIntegration(); builder.UseIISIntegration();

View File

@ -17,6 +17,9 @@ using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Server.IISIntegration namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
/// <summary>
/// The middleware that enables IIS Out-Of-Process to work.
/// </summary>
public class IISMiddleware public class IISMiddleware
{ {
private const string MSAspNetCoreClientCert = "MS-ASPNETCORE-CLIENTCERT"; private const string MSAspNetCoreClientCert = "MS-ASPNETCORE-CLIENTCERT";
@ -34,6 +37,15 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
private readonly IHostApplicationLifetime _applicationLifetime; private readonly IHostApplicationLifetime _applicationLifetime;
private readonly bool _isWebsocketsSupported; private readonly bool _isWebsocketsSupported;
/// <summary>
/// The middleware that enables IIS Out-Of-Process to work.
/// </summary>
/// <param name="next">The next middleware in the pipeline.</param>
/// <param name="loggerFactory">The <see cref="ILoggerFactory" />.</param>
/// <param name="options">The configuration for this middleware.</param>
/// <param name="pairingToken">A token used to coordinate with the ASP.NET Core Module.</param>
/// <param name="authentication">The <see cref="IAuthenticationSchemeProvider"/>.</param>
/// <param name="applicationLifetime">The <see cref="IHostApplicationLifetime"/>.</param>
// Can't break public API, so creating a second constructor to propagate the isWebsocketsSupported flag. // Can't break public API, so creating a second constructor to propagate the isWebsocketsSupported flag.
public IISMiddleware(RequestDelegate next, public IISMiddleware(RequestDelegate next,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
@ -45,6 +57,16 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
} }
/// <summary>
/// The middleware that enables IIS Out-Of-Process to work.
/// </summary>
/// <param name="next">The next middleware in the pipeline.</param>
/// <param name="loggerFactory">The <see cref="ILoggerFactory" />.</param>
/// <param name="options">The configuration for this middleware.</param>
/// <param name="pairingToken">A token used to coordinate with the ASP.NET Core Module.</param>
/// <param name="isWebsocketsSupported">Whether websockets are supported by IIS.</param>
/// <param name="authentication">The <see cref="IAuthenticationSchemeProvider"/>.</param>
/// <param name="applicationLifetime">The <see cref="IHostApplicationLifetime"/>.</param>
public IISMiddleware(RequestDelegate next, public IISMiddleware(RequestDelegate next,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IOptions<IISOptions> options, IOptions<IISOptions> options,
@ -88,6 +110,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
_isWebsocketsSupported = isWebsocketsSupported; _isWebsocketsSupported = isWebsocketsSupported;
} }
/// <summary>
/// Invoke the middleware.
/// </summary>
/// <param name="httpContext">The <see cref="HttpContext"/>.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
public async Task Invoke(HttpContext httpContext) public async Task Invoke(HttpContext httpContext)
{ {
if (!string.Equals(_pairingToken, httpContext.Request.Headers[MSAspNetCoreToken], StringComparison.Ordinal)) if (!string.Equals(_pairingToken, httpContext.Request.Headers[MSAspNetCoreToken], StringComparison.Ordinal))

View File

@ -3,6 +3,9 @@
namespace Microsoft.AspNetCore.Builder namespace Microsoft.AspNetCore.Builder
{ {
/// <summary>
/// Options to configure IIS Out-Of-Process.
/// </summary>
public class IISOptions public class IISOptions
{ {
/// <summary> /// <summary>

View File

@ -1,16 +1,16 @@
<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>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<IsAspNetCoreApp>true</IsAspNetCoreApp> <IsAspNetCoreApp>true</IsAspNetCoreApp>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;iis</PackageTags> <PackageTags>aspnetcore;iis</PackageTags>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<!-- Ignore platform compatibility warnings for this project. We know this only works on windows.--> <!-- Ignore platform compatibility warnings for this project. We know this only works on windows.-->
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
<NoWarn>$(NoWarn);CA1416</NoWarn> <NoWarn>$(NoWarn);CA1416</NoWarn>
</PropertyGroup> </PropertyGroup>

View File

@ -11,6 +11,9 @@ using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Hosting namespace Microsoft.AspNetCore.Hosting
{ {
/// <summary>
/// Extension methods for the IIS Out-Of-Process.
/// </summary>
public static class WebHostBuilderIISExtensions public static class WebHostBuilderIISExtensions
{ {
// These are defined as ASPNETCORE_ environment variables by IIS's AspNetCoreModule. // These are defined as ASPNETCORE_ environment variables by IIS's AspNetCoreModule.

View File

@ -4,7 +4,6 @@
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<PackageId>Microsoft.AspNetCore.Server.IntegrationTesting.IIS</PackageId> <PackageId>Microsoft.AspNetCore.Server.IntegrationTesting.IIS</PackageId>
<Description>Provides support for integration testing using IIS based servers.</Description> <Description>Provides support for integration testing using IIS based servers.</Description>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;iis</PackageTags> <PackageTags>aspnetcore;iis</PackageTags>
<DisableFastUpToDateCheck>True</DisableFastUpToDateCheck> <DisableFastUpToDateCheck>True</DisableFastUpToDateCheck>