-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Servers > ANCM update #5538
Servers > ANCM update #5538
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,59 @@ | ||
--- | ||
title: ASP.NET Core Module | ||
title: ASP.NET Core Module for ASP.NET Core | ||
author: tdykstra | ||
description: Introduces ASP.NET Core Module (ANCM), an IIS module that lets the Kestrel web server use IIS or IIS Express as a reverse proxy server. | ||
description: Learn how the ASP.NET Core Module is an IIS module that allows the Kestrel web server use IIS or IIS Express as a reverse proxy server. | ||
manager: wpickett | ||
ms.author: tdykstra | ||
ms.custom: H1Hack27Feb2017 | ||
ms.date: 08/03/2017 | ||
ms.custom: mvc | ||
ms.date: 02/23/2018 | ||
ms.prod: asp.net-core | ||
ms.technology: aspnet | ||
ms.topic: article | ||
uid: fundamentals/servers/aspnet-core-module | ||
--- | ||
# Introduction to ASP.NET Core Module | ||
# ASP.NET Core Module for ASP.NET Core | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant? |
||
|
||
By [Tom Dykstra](https://github.com/tdykstra), [Rick Strahl](https://github.com/RickStrahl), and [Chris Ross](https://github.com/Tratcher) | ||
|
||
ASP.NET Core Module (ANCM) lets you run ASP.NET Core applications behind IIS, using IIS for what it's good at (security, manageability, and lots more) and using [Kestrel](kestrel.md) for what it's good at (being really fast), and getting the benefits from both technologies at once. **ANCM works only with Kestrel; it isn't compatible with WebListener (in ASP.NET Core 1.x) or HTTP.sys (in 2.x).** | ||
The ASP.NET Core Module allows ASP.NET Core apps to run behind IIS in a reverse proxy configuration. IIS provides advanced web app security and manageability features. [Kestrel](xref:fundamentals/servers/kestrel) provides fast request processing. Creating a reverse proxy between Kestrel and IIS provides the benefits of both technologies. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The performance is actually much worse than directly using Kestrel. Really what you get is a consistent application model across platforms. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
... you mean Kestrel does? I thought Tom (or whoever wrote this) was saying that Kestrel is faster than the ASP.NET 4.x runtime at processing requests. I thought he was saying IIS+ANCM+Kestrel is faster than IIS+ASP.NET 4.x. We could dump the foul (and confusing 😵) contrast by dropping the end of the paragraph. The para becomes ...
|
||
|
||
Supported Windows versions: | ||
|
||
* Windows 7 and Windows Server 2008 R2 and later | ||
* Windows 7 or later | ||
* Windows Server 2008 R2 or later† | ||
|
||
[View or download sample code](https://github.com/aspnet/Docs/tree/master/aspnetcore/fundamentals/servers/aspnet-core-module/sample) ([how to download](xref:tutorials/index#how-to-download-a-sample)) | ||
†Conceptually, the use of the ASP.NET Core Module with IIS described in this document also applies to hosting ASP.NET Core apps on Nano Server IIS. For instructions specific to Nano Server, see the [ASP.NET Core with IIS on Nano Server](xref:tutorials/nano-server) tutorial. | ||
|
||
## What ASP.NET Core Module does | ||
The ASP.NET Core Module only works with Kestrel. The module is incompatible with [HTTP.sys](xref:fundamentals/servers/httpsys) (formerly called [WebListener](xref:fundamentals/servers/weblistener)). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will need to update this document based on our new inprocess feature. cc/ @shirhatti . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
ANCM is a native IIS module that hooks into the IIS pipeline and redirects traffic to the backend ASP.NET Core application. Most other modules, such as windows authentication, still get a chance to run. ANCM only takes control when a handler is selected for the request, and handler mapping is defined in the application *web.config* file. | ||
## ASP.NET Core Module description | ||
|
||
Because ASP.NET Core applications run in a process separate from the IIS worker process, ANCM also does process management. ANCM starts the process for the ASP.NET Core application when the first request comes in and restarts it when it crashes. This is essentially the same behavior as classic ASP.NET applications that run in-process in IIS and are managed by WAS (Windows Activation Service). | ||
The ASP.NET Core Module is a native IIS module that plugs into the IIS pipeline to redirect web requests to backend ASP.NET Core apps. Many native modules, such as Windows Authentication, remain active. To learn more about IIS modules active with the module, see [Using IIS modules](xref:host-and-deploy/iis/modules). | ||
|
||
Here's a diagram that illustrates the relationship between IIS, ANCM, and ASP.NET Core applications. | ||
Because ASP.NET Core apps run in a process separate from the IIS worker process, the module also handles process management. The module starts the process for the ASP.NET Core app when the first request arrives and restarts the app if it crashes. This is essentially the same behavior as seen with ASP.NET 4.x apps that run in-process in IIS that are managed by the [Windows Process Activation Service (WAS)](/iis/manage/provisioning-and-managing-iis/features-of-the-windows-process-activation-service-was). | ||
|
||
![ASP.NET Core Module](aspnet-core-module/_static/ancm.png) | ||
|
||
Requests come in from the Web and hit the kernel mode Http.Sys driver which routes them into IIS on the primary port (80) or SSL port (443). ANCM forwards the requests to the ASP.NET Core application on the HTTP port configured for the application, which isn't port 80/443. | ||
|
||
Kestrel listens for traffic coming from ANCM. ANCM specifies the port via environment variable at startup, and the [UseIISIntegration](#call-useiisintegration) method configures the server to listen on `http://localhost:{port}`. There are additional checks to reject requests not from ANCM. (ANCM doesn't support HTTPS forwarding, so requests are forwarded over HTTP even if received by IIS over HTTPS.) | ||
|
||
Kestrel picks up requests from ANCM and pushes them into the ASP.NET Core middleware pipeline, which then handles them and passes them on as `HttpContext` instances to application logic. The application's responses are then passed back to IIS, which pushes them back out to the HTTP client that initiated the requests. | ||
|
||
ANCM has a few other functions as well: | ||
|
||
* Sets environment variables. | ||
* Logs `stdout` output to file storage. | ||
* Forwards Windows authentication tokens. | ||
|
||
## How to use ANCM in ASP.NET Core apps | ||
|
||
This section provides an overview of the process for setting up an IIS server and ASP.NET Core application. For detailed instructions, see [Host on Windows with IIS](xref:host-and-deploy/iis/index). | ||
|
||
### Install ANCM | ||
|
||
The ANCM is installed in IIS on Windows Server and in IIS Express on Windows desktop operating systems. For servers and development machines, the ANCM is included in the [.NET Core Windows Server Hosting bundle](https://aka.ms/dotnetcore-2-windowshosting). If installing Visual Studio, the ANCM is automatically installed in IIS Express (and in IIS, if present on the machine). | ||
|
||
### .NET Core Windows Server Hosting bundle | ||
|
||
The [.NET Core Windows Server Hosting bundle](https://aka.ms/dotnetcore-2-windowshosting) installs the .NET Core Runtime, .NET Core Library, and the ANCM. For more information, see [Install the .NET Core Windows Server Hosting bundle]( | ||
xref:host-and-deploy/iis/index#install-the-net-core-windows-server-hosting-bundle). | ||
|
||
### Install the IISIntegration NuGet package | ||
|
||
# [ASP.NET Core 2.x](#tab/aspnetcore2x) | ||
|
||
The [Microsoft.AspNetCore.Server.IISIntegration](https://www.nuget.org/packages/Microsoft.AspNetCore.Server.IISIntegration/) package is included in the ASP.NET Core metapackages ([Microsoft.AspNetCore](https://www.nuget.org/packages/Microsoft.AspNetCore/) and [Microsoft.AspNetCore.All](xref:fundamentals/metapackage)). If you don't use one of the metapackages, install `Microsoft.AspNetCore.Server.IISIntegration` separately. The `IISIntegration` package is an interoperability pack that reads environment variables broadcast by ANCM to set up your app. The environment variables provide configuration information, such as the port to listen on. | ||
|
||
# [ASP.NET Core 1.x](#tab/aspnetcore1x) | ||
|
||
In your application, install [Microsoft.AspNetCore.Server.IISIntegration](https://www.nuget.org/packages/Microsoft.AspNetCore.Server.IISIntegration/). The `IISIntegration` package is an interoperability pack that reads environment variables broadcast by ANCM to set up your app. The environment variables provide configuration information, such as the port to listen on. | ||
|
||
--- | ||
The following diagram illustrates the relationship between IIS, the ASP.NET Core Module, and ASP.NET Core apps: | ||
|
||
### Call UseIISIntegration | ||
|
||
# [ASP.NET Core 2.x](#tab/aspnetcore2x) | ||
|
||
The `UseIISIntegration` extension method on [`WebHostBuilder`](https://docs.microsoft.com/aspnet/core/api/microsoft.aspnetcore.hosting.webhostbuilder) is called automatically when you run with IIS. | ||
|
||
If you aren't using one of the ASP.NET Core metapackages and haven't installed the `Microsoft.AspNetCore.Server.IISIntegration` package, you get a runtime error. If you call `UseIISIntegration` explicitly, you get a compile time error if the package isn't installed. | ||
|
||
# [ASP.NET Core 1.x](#tab/aspnetcore1x) | ||
|
||
In your application's `Main` method, call the `UseIISIntegration` extension method on [`WebHostBuilder`](https://docs.microsoft.com/aspnet/core/api/microsoft.aspnetcore.hosting.webhostbuilder). | ||
|
||
[!code-csharp[](aspnet-core-module/sample/Program.cs?name=snippet_Main&highlight=12)] | ||
|
||
--- | ||
|
||
The `UseIISIntegration` method looks for environment variables that ANCM sets, and it no-ops if they aren't found. This behavior facilitates scenarios like developing and testing on macOS or Linux and deploying to a server that runs IIS. While running on macOS or Linux, Kestrel acts as the web server; but when the app is deployed to the IIS environment, it automatically uses ANCM and IIS. | ||
|
||
### ANCM port binding overrides other port bindings | ||
|
||
# [ASP.NET Core 2.x](#tab/aspnetcore2x) | ||
|
||
ANCM generates a dynamic port to assign to the back-end process. The `UseIISIntegration` method picks up this dynamic port and configures Kestrel to listen on `http://locahost:{dynamicPort}/`. This overrides other URL configurations, such as calls to `UseUrls` or [Kestrel's Listen API](xref:fundamentals/servers/kestrel?tabs=aspnetcore2x#endpoint-configuration). Therefore, you don't need to call `UseUrls` or Kestrel's `Listen` API when you use ANCM. If you do call `UseUrls` or `Listen`, Kestrel listens on the port you specify when you run the app without IIS. | ||
|
||
# [ASP.NET Core 1.x](#tab/aspnetcore1x) | ||
|
||
ANCM generates a dynamic port to assign to the back-end process. The `UseIISIntegration` method picks up this dynamic port and configures Kestrel to listen on `http://locahost:{dynamicPort}/`. This overrides other URL configurations, such as calls to `UseUrls`. Therefore, you don't need to call `UseUrls` when you use ANCM. If you do call `UseUrls`, Kestrel listens on the port you specify when you run the app without IIS. | ||
|
||
In ASP.NET Core 1.0, if you call `UseUrls`, call it **before** you call `UseIISIntegration` so that the ANCM-configured port doesn't get overwritten. This calling order isn't required in ASP.NET Core 1.1, because the ANCM setting overrides `UseUrls`. | ||
|
||
--- | ||
|
||
### Configure ANCM options in Web.config | ||
![ASP.NET Core Module](aspnet-core-module/_static/ancm.png) | ||
|
||
Configuration for the ASP.NET Core Module is stored in the *web.config* file that's located in the application's root folder. Settings in this file point to the startup command and arguments that start your ASP.NET Core app. For sample *web.config* code and guidance on configuration options, see [ASP.NET Core Module Configuration Reference](xref:host-and-deploy/aspnet-core-module). | ||
Requests arrive from the web to the kernel-mode HTTP.sys driver. The driver routes the requests to IIS on the website's configured port, usually 80 (HTTP) or 443 (HTTPS). The module forwards the requests to Kestrel on a dynamically-configured port for the app, which isn't port 80/443. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think dynamically configured should be replaced by random, as there is nothing to configure for what port is selected. |
||
|
||
### Run with IIS Express in development | ||
The module specifies the dynamic port via an environment variable at startup, and the IIS Integration Middleware configures the server to listen on `http://localhost:{port}`. Additional checks are performed, and requests that don't originate from the module are rejected. The module doesn't support HTTPS forwarding, so requests are forwarded over HTTP even if received by IIS over HTTPS. | ||
|
||
IIS Express can be launched by Visual Studio using the default profile defined by the ASP.NET Core templates. | ||
After Kestrel picks up a request from the module, the request is pushed into the ASP.NET Core middleware pipeline. The middleware pipeline handles the request and passes it on as an `HttpContext` instance to the app's logic. The app's response is passed back to IIS, which pushes it back out to the HTTP client that initiated the request. | ||
|
||
## Proxy configuration uses HTTP protocol and a pairing token | ||
The ASP.NET Core Module has a few other functions. The module can: | ||
|
||
The proxy created between the ANCM and Kestrel uses the HTTP protocol. Using HTTP is a performance optimization where the traffic between the ANCM and Kestrel takes place on a loopback address off of the network interface. There's no risk of eavesdropping the traffic between the ANCM and Kestrel from a location off of the server. | ||
* Set environment variables for the worker process. | ||
* Log `stdout` output to file storage for troubleshooting startup issues. | ||
* Forward Windows authentication tokens. | ||
|
||
A pairing token is used to guarantee that the requests received by Kestrel were proxied by IIS and didn't come from some other source. The pairing token is created and set into an environment variable (`ASPNETCORE_TOKEN`) by the ANCM. The pairing token is also set into a header (`MSAspNetCoreToken`) on every proxied request. IIS Middleware checks each request it receives to confirm that the pairing token header value matches the environment variable value. If the token values are mismatched, the request is logged and rejected. The pairing token environment variable and the traffic between the ANCM and Kestrel aren't accessible from a location off of the server. Without knowing the pairing token value, an attacker can't submit requests that bypass the check in the IIS Middleware. | ||
## How to install and use the ASP.NET Core Module | ||
|
||
## Next steps | ||
For detailed instructions on how to install and use the ASP.NET Core Module, see [Host on Windows with IIS](xref:host-and-deploy/iis/index). For information on configuring the module, see the [ASP.NET Core Module configuration reference](xref:host-and-deploy/aspnet-core-module). | ||
|
||
For more information, see the following resources: | ||
## Additional resources | ||
|
||
* [Sample app for this article](https://github.com/aspnet/Docs/tree/master/aspnetcore/fundamentals/servers/aspnet-core-module/sample) | ||
* [ASP.NET Core Module source code](https://github.com/aspnet/AspNetCoreModule) | ||
* [ASP.NET Core Module Configuration Reference](xref:host-and-deploy/aspnet-core-module) | ||
* [Host on Windows with IIS](xref:host-and-deploy/iis/index) | ||
* [ASP.NET Core Module configuration reference](xref:host-and-deploy/aspnet-core-module) | ||
* [ASP.NET Core Module GitHub repository (source code)](https://github.com/aspnet/AspNetCoreModule) |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to revert this (or anything you like here). Just give the word.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence doesn't parse
"Learn about the ASP.NET Core Module, an IIS module that allows the Kestrel web server to use IIS or IIS Express as a reverse proxy server."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ... yes ... "TO" missing a "to" in there ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my version is slightly more definitive and active.
Learn about something, where something is something that does something.
vs.
Learn how something is something that does something.
Shall we turn to @scottaddie to break the tie??!! 😄 lol
or