Deploy Web API net Core to IIS
By Luke Latham and Rick Anderson Show
Supported operating systems¶The following operating systems are supported:
*Conceptually, the IIS configuration described in this document also applies to hosting ASP.NET Core applications on Nano Server IIS, but refer to ASP.NET Core on Nano Server for specific instructions. IIS configuration¶Enable the Web Server (IIS) server role and establish role services. Windows desktop operating systems¶Navigate to Control Panel > Programs > Programs and Features > Turn Windows features on or off (left side of the screen). Open the group for Internet Information Services and Web Management Tools. Check the box for IIS Management Console. Check the box for World Wide Web Services. Accept the default features for World Wide Web Services or customize the IIS features to suit your needs. Windows Server operating systems¶For server operating systems, use the Add Roles and Features Wizard via the Manage menu or the link in Server Manager. On the Server Roles step, check the box for Web Server (IIS). On the Role services step, select the IIS role services you desire or accept the default role services provided. Proceed through the Confirmation step to enable the web server role and services. Install the .NET Core Windows Server Hosting bundle¶
For more information on the ASP.NET Core Module, including configuration of the module and setting environment variables with web.config, the use of app_offline.htm to suspend request processing, and activation of module logging, see ASP.NET Core Module Configuration Reference. Application configuration¶Enabling the IISIntegration components¶Include a dependency on the Microsoft.AspNetCore.Server.IISIntegration package in the application dependencies. Incorporate IIS Integration middleware into the application by adding the .UseIISIntegration() extension method to WebHostBuilder(). var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); Note that code calling .UseIISIntegration() does not affect code portability. Setting IISOptions for the IISIntegration service¶To configure IISIntegration service options, include a service configuration for IISOptions in ConfigureServices. services.Configure<IISOptions>(options => { ... });
Deploy the application¶
Warning .NET Core applications are hosted via a reverse-proxy between IIS and the Kestrel server. In order to create the reverse-proxy, the web.config file must be present at the content root path (typically the app base path) of the deployed application, which is the website physical path provided to IIS. Sensitive files exist on the app’s physical path, including subfolders, such as my_application.runtimeconfig.json, my_application.xml (XML Documentation comments), and my_application.deps.json. The web.config file is required to create the reverse proxy to Kestrel, which prevents IIS from serving these and other sensitive files. Therefore, it is important that the web.config file is never accidently renamed or removed from the deployment. Configure the website in IIS¶
Note If you change the default identity of the application pool from ApplicationPoolIdentity, verify the new identity has the required permissions to access the application’s assets and database. Open the Add Website window. Configure the website. In the Application Pools panel, open the Edit Application Pool window by right-clicking on the website’s application pool and selecting Basic Settings... from the popup menu. Set the .NET CLR version to No Managed Code. Browse the website. Create a Data Protection Registry Hive¶Data Protection keys used by ASP.NET applications are stored in registry hives external to the applications. To persist the keys for a given application, you must create a registry hive for the application’s application pool. For standalone IIS installations, you may use the Data Protection Provision-AutoGenKeys.ps1 PowerShell script for each application pool used with an ASP.NET Core application. The keys will be persisted in the registry. In web farm scenarios, an application can be configured to use a UNC path to store its data protection key ring. By default, the data protection keys are not encrypted. You can deploy an x509 certificate to each machine to encrypt the key ring. See Configuring Data Protection for details. Warning Data Protection is used by various ASP.NET middlewares, including those used in authentication. Even if you do not specifically call any Data Protection APIs from your own code you should configure Data Protection with the deployment script or in your own code. If you do not configure data protection when using IIS by default the keys will be held in memory and discarded when your application closes or restarts. This will then, for example, invalidate any cookies written by the cookie authentication and users will have to login again. Common errors¶The following is not a complete list of errors. Should you encounter an error not listed here, please leave a detailed error message in the DISQUS section below (click Show comments to open the DISQUS panel). To diagnose problems with IIS deployments, study browser output, examine the server’s Application log through Event Viewer, and enable module logging. The ASP.NET Core Module log will be found on the path provided in the stdoutLogFile attribute of the Several of the common errors do not appear in the browser, Application Log, and ASP.NET Core Module Log until the module startupTimeLimit (default: 120 seconds) and startupRetryCount (default: 2) have passed. Therefore, wait a full six minutes before deducing that the module has failed to start a process for the application. A quick way to determine if the application is working properly is to run the application directly on Kestrel. If the application was published as a portable app, execute
dotnet A way to determine if the IIS reverse proxy to the Kestrel server is working properly is to perform a simple static file request for a stylesheet, script, or image from the application’s static assets in wwwroot using Static File middleware. If the application can serve static files but MVC Views and other endpoints are failing, the problem is less likely related to the IIS-ASP.NET Core Module-Kestrel configuration and more likely within the application itself (for example, MVC routing or 500 Internal Server Error). In most cases, enabling application logging will assist in troubleshooting problems with application or the reverse proxy. See Logging for more information. Common errors and general troubleshooting instructions: Installer unable to obtain VC++ Redistributable¶
Troubleshooting:
Platform conflicts with RID¶
Troubleshooting:
URI endpoint wrong or stopped website¶
Troubleshooting:
CoreWebEngine or W3SVC server features disabled¶
Troubleshooting:
Incorrect website physical path or application missing¶
Troubleshooting:
Incorrect server role, module not installed, or incorrect permissions¶
Troubleshooting:
Hosting bundle not installed or server not restarted¶
Troubleshooting:
Incorrect proecessPath, missing PATH variable, or dotnet.exe access violation¶
Troubleshooting:
Incorrect arguments of |