{"id":12065,"date":"2018-02-28T17:56:02","date_gmt":"2018-03-01T00:56:02","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/?p=12065"},"modified":"2018-02-28T17:56:02","modified_gmt":"2018-03-01T00:56:02","slug":"asp-net-core-2-1-0-preview1-improvements-to-iis-hosting","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/asp-net-core-2-1-0-preview1-improvements-to-iis-hosting\/","title":{"rendered":"ASP.NET Core 2.1.0-preview1: Improvements to IIS hosting"},"content":{"rendered":"<div>\n<div>\n    <span>The ASP.NET Core Module (ANCM) is a global IIS module that has been responsible for proxying requests over from IIS to your backend ASP.NET Core application running Kestrel.\u00a0<\/span><span>Since 2.0 we have been hard at work to bring to two major improvements to ANCM: version agility and performance. <\/span>\n  <\/div>\n<div>\n    Note, that in the 2.1.0-preview1 release, we have chosen <strong>not<\/strong> to update the global module by default, to avoid impacting any existing 1.x\/2.0 applications at this early stage. This post details the changes in ANCM and how you can opt-in to trying out these changes today.\n  <\/div>\n<\/div>\n<h2>Version agility<\/h2>\n<div>\n<div>\n    <span>It has been hard to iterate on ANCM since we&#8217;ve had to ensure forward and backward compatibility between every version of ASP.NET Core and ANCM that has shipped thus far.\u00a0<\/span><span>To mitigate this problem going forward, we&#8217;ve refactored our code into two separate components: the ASP.NET Core Shim (shim), and the ASP.NET Core Request Handler (request handler). The shim (aspnetcore.dll), as the name suggests, is a lightweight shim, where as the request handler (aspnetcorerh.dll) does all the request processing.<\/span><span>Going forward, the shim will ship globally and will continue to be installed via the Windows Server Hosting installer. The request handler will now ship via a NuGet package- <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.AspNetCore.Server.IIS\">Microsoft.AspNetCore.Server.IIS<\/a>, which you can directly reference in your application or consume via the ASP.NET Core metapackage or shared runtime. As a consequence, two different ASP.NET Core applications running on the same server can use a different version of the request handler.<\/span>\n  <\/div>\n<div>\n  <\/div>\n<\/div>\n<h2>Performance<\/h2>\n<div>\n<div>\n    <span>In addition\u00a0to the packaging changes, ANCM also adds supports for an in-process hosting model for ASP.NET Core applications running on .NET Core. Instead of serving as a reverse-proxy, ANCM can now boot the CoreCLR and host your application inside the IIS worker process (w3wp.exe). Our preliminary\u00a0performance tests have shown that this model delivers <strong>4.4x<\/strong> the request throughput compared to hosting your .NET Core application out-of-process and proxying over the requests.<\/span>\n  <\/div>\n<div>\n  <\/div>\n<\/div>\n<h2 id=\"howdoitryit\">How do I try it?<\/h2>\n<div>\n<div>\n    <span>If you have already installed the <\/span><a href=\"https:\/\/download.microsoft.com\/download\/A\/B\/1\/AB1AA972-8F2F-43AD-9A81-72E9245CB0F5\/dotnet-hosting-2.1.0-preview1-final-win.exe\"><span>2.1.0-preview1 Windows Server Hosting bundle<\/span><\/a><span>, you can install the latest ANCM by running this <\/span><a href=\"https:\/\/raw.githubusercontent.com\/shirhatti\/ANCM-ARMTemplate\/b13de5f65b8c524d9ce72da5fd8df774e0eb76da\/install-ancm.ps1\"><span>script<\/span><\/a><span>.<\/span>\n  <\/div>\n<\/div>\n<div>\n  Alternatively, you can deploy an Azure VM which is already setup with the latest ANCM by clicking the\u00a0<a href=\"https:\/\/portal.azure.com\/#create\/Microsoft.Template\/uri\/https%3A%2F%2Fraw.githubusercontent.com%2Fshirhatti%2FANCM-ARMTemplate%2Fmaster%2Fazuredeploy.json\">Deploy to Azure<\/a>\u00a0button below.<a target=\"_blank\" href=\"https:\/\/portal.azure.com\/#create\/Microsoft.Template\/uri\/https%3A%2F%2Fraw.githubusercontent.com%2Fshirhatti%2FANCM-ARMTemplate%2Fmaster%2Fazuredeploy.json\" rel=\"noopener noreferrer\"> <img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/deploybutton-2.png\" \/><\/a><a target=\"_blank\" href=\"https:\/\/armviz.io\/#\/?load=https%3A%2F%2Fraw.githubusercontent.com%2Fshirhatti%2FANCM-ARMTemplate%2Fmaster%2Fazuredeploy.json\" rel=\"noopener noreferrer\">\u00a0<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/visualizebutton-2.png\" \/> <\/a>\n<\/div>\n<div>\n<\/div>\n<div>\n<div>\n<h2>\n      <span>Create a new project or update your existing project<\/span>\n    <\/h2>\n<div>\n<div>\n        <span>Now that we have an environment to publish to, let&#8217;s create a new application that targets 2.1.0-preview1 of ASP.NET Core.<\/span>\n      <\/div>\n<div>\n        <span>Alternatively, you can upgrade an existing project by following the instructions on\u00a0<\/span><a href=\"https:\/\/devblogs.microsoft.com\/aspnet\/asp-net-core-2-1-0-preview1-now-available\/\"><span>this post<\/span><\/a><span>.<\/span>\n      <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div>\n<\/div>\n<h2>Modify your project<\/h2>\n<div>\n<div>\n<div>\n      <span>Let&#8217;s go ahead and modify our project by setting a project property to indicate that we want our published application to be run <strong><em>inprocess<\/em><\/strong>.<\/span>\n    <\/div>\n<div>\n    <\/div>\n<div>\n      Add this to your <em><strong>csproj<\/strong><\/em> file.\n    <\/div>\n<\/p><\/div>\n<\/div>\n<h2>Publish your project<\/h2>\n<div>\n<div>\n    <span>Create a new publish profile and select the Azure VM that you just created. If you&#8217;re using Visual Studio, you can easily publish to the Azure VM you just created. In the <\/span><span><strong>Solution Explorer<\/strong><\/span><span>, right-click the project and select <\/span><span><strong>Publish<\/strong><\/span><span>\u00a0to open the Publish wizard where you can choose to publish to an Azure VM that you just created.<\/span>\n  <\/div>\n<div>\n  <\/div>\n<div>\n    <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/publish-azure-vm-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/publish-azure-vm-1-1.png\" alt=\"\" width=\"800\" height=\"600\" class=\"size-full wp-image-12115 alignnone\" \/><\/a>\n  <\/div>\n<\/div>\n<div>\n<\/div>\n<div>\n<div>\n<div>\n      <span>You may need to allow WebDeploy to publish to a server using an untrusted certificate. This can be accomplished by adding the following attribute to your publish profile (<\/span><strong>.pubxml<\/strong><span>\u00a0file)<\/span>\n    <\/div>\n<\/p><\/div>\n<div>\n  <\/div>\n<\/div>\n<div>\n<\/div>\n<div>\n<div>\n<div>\n      <span>If you&#8217;re running elsewhere, go ahead and publish your app to a Folder and copy over your artifacts, or publish directly via WebDeploy.<\/span>\n    <\/div>\n<\/p><\/div>\n<\/div>\n<h4>web.config<\/h4>\n<div>\n<div>\n    <span>As part of the publish process, the Web SDK will read the <\/span><em>AspNetCoreModuleHostingModel<\/em><span>\u00a0property and transform your <strong>web.config<\/strong>\u00a0to look something like this (observe the new <em>hostingModel<\/em> attribute):<\/span>\n  <\/div>\n<div>\n  <\/div>\n<\/div>\n<h2>Debugging<\/h2>\n<div>\n<blockquote>\n<div>\n      <span>To view the Cloud Explorer, select <\/span><strong>View<\/strong><span>\u00a0&gt; <\/span><strong>Cloud Explorer<\/strong><span>\u00a0on the menu bar<\/span>\n    <\/div>\n<\/blockquote>\n<div>\n<div>\n      <span>If you&#8217;ve been following along using an Azure VM, you can enable remote debugging on your Azure VM via the cloud explorer. In the <\/span><strong>Actions<\/strong><span>\u00a0tab associated with your VM, you should be able to <\/span><span><strong>Enable Debugging<\/strong><\/span><span>.<\/span>\n    <\/div>\n<div>\n      <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/enable-remote-debugging.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/enable-remote-debugging-2.png\" alt=\"\" width=\"304\" height=\"559\" class=\"size-full wp-image-12105 alignnone\" \/><\/a>\n    <\/div>\n<\/p><\/div>\n<\/div>\n<div>\n  Once you&#8217;ve enabled remote debugging, you should be able to attach directly to the w3wp.exe process. If you don&#8217;t see the process listed, you may need to send a request to your server to force IIS to start the worker process.\n<\/div>\n<div>\n<div>\n  <\/div>\n<div>\n    <span>If you&#8217;ve been following along locally, you can use Visual Studio to attach directly to your IIS worker process and debug your application code running in the IIS worker process as shown below. (You may be prompted to restart Visual Studio as an Administrator for this).<\/span>\n  <\/div>\n<\/div>\n<div>\n<div>\n<blockquote>\n<div>\n        <span>We don&#8217;t yet have an experience for debugging with IIS Express. At the moment, you will have to publish to IIS and then attach a debugger.<\/span>\n      <\/div>\n<\/blockquote>\n<div>\n      <a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/attach-debugger.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2018\/02\/attach-debugger-2.png\" alt=\"\" width=\"978\" height=\"807\" class=\"size-full wp-image-12095 alignnone\" \/><\/a>\n    <\/div>\n<\/p><\/div>\n<div>\n<div>\n<h2>\n        <span>Switching between in-process and out-of-process<\/span>\n      <\/h2>\n<div>\n<div>\n          <span>Switching hosting models can be a deployment-time decision. To change between hosting models, all you have to do is change the <\/span><em><strong>hostingModel<\/strong><\/em><span>\u00a0attribute in your web.config from <\/span><span><em><strong>inprocess<\/strong><\/em><\/span><span>\u00a0to <\/span><span><em><strong>outofprocess<\/strong><\/em><\/span><span>.<\/span>\n        <\/div>\n<\/p><\/div>\n<div>\n      <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div>\n<div>\n<div>\n<div>\n<div>\n<div>\n          <\/div>\n<div>\n            <span>It can be easily seen in this simple app where you&#8217;ll observe either <\/span><span><em>Hello World from dotnet<\/em><\/span><span>\u00a0or <\/span><span><em>Hello World from w3wp<\/em><\/span><span>\u00a0based on your hosting model.<\/span>\n          <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The ASP.NET Core Module (ANCM) is a global IIS module that has been responsible for proxying requests over from IIS to your backend ASP.NET Core application running Kestrel.\u00a0Since 2.0 we have been hard at work to bring to two major improvements to ANCM: version agility and performance. Note, that in the 2.1.0-preview1 release, we have [&hellip;]<\/p>\n","protected":false},"author":1233,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197,7509],"tags":[],"class_list":["post-12065","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","category-aspnetcore"],"acf":[],"blog_post_summary":"<p>The ASP.NET Core Module (ANCM) is a global IIS module that has been responsible for proxying requests over from IIS to your backend ASP.NET Core application running Kestrel.\u00a0Since 2.0 we have been hard at work to bring to two major improvements to ANCM: version agility and performance. Note, that in the 2.1.0-preview1 release, we have [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/12065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/1233"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=12065"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/12065\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=12065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=12065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=12065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}