Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

Publishing and Running ASP.NET Core Applications with IIS


:P
On this page:

When you build ASP.NET Core applications and plan on running them on IIS, you'll find that .NET Core applications in IIS work radically different than previous versions of ASP.NET.

In this post I'll explain how ASP.NET Core runs in the context of IIS and how you can deploy your ASP.NET Core application to IIS.

IIS and ASP.NET Core

The most important thing to understand about hosting ASP.NET Core is that it runs as a standalone, out of process Console application. It's not hosted inside of IIS and it doesn't need IIS to run. ASP.NET Core applications have their own self-hosted Web server and process requests internally using this self-hosted server instance.

You can however run IIS as a front end proxy for ASP.NET Core applications, because Kestrel is a raw Web server that doesn't support all features a full server like IIS supports. This is actually a recommended practice on Windows in order to provide port 80/443 forwarding which kestrel doesn't support directly. For Windows IIS (or another reverse proxy) will continue to be an important part of the server even with ASP.NET Core applications.

Let's take a look and see how IIS fits into ASP.NET Core applications.

Classic ASP.NET Hosting

Before we take a look at ASP.NET Core hosting lets review how classic ASP.NET runs ASP.NET applications:

Hosting ASP.NET on IIS

In a classic ASP.NET application everything is hosted inside of an IIS Worker Process (w3wp.exe) which is the IIS Application Pool. The AppPool hosts your ASP.NET application and your application is instantiated by the built-in ASP.NET hosting features in IIS. The native runtime manager instantiates the .NET Runtime on your application's behalf and brings up the HttpRuntime object which is then used to fire requests through the ASP.NET application pipeline as requests come in from the native http.sys driver. Requests come in from http.sys and are dispatched to the appropriate site that is mapped to the Application Pool and the HttpRuntime instance hosted there.

ASP.NET Core with IIS

Things are quite different with ASP.NET Core which doesn't run in-process to the IIS worker process, but rather runs as a separate, out of process Console application that runs its own Web server using the Kestrel component. Kestrel is a .NET Web Server implementation that has been heavily optimized for throughput performance. It's fast and functional in getting network requests into your application, but it's 'just' a raw Web server. It does not include Web management services as a full featured server like IIS does.

As of ASP.NET Core 2.2 IIS Hosting does support a new InProcess hosting mechanism. A seperate post describes the details of In Process/Out of Process hosting.

If you run on Windows you will likely want to run Kestrel behind IIS to gain infrastructure features like port 80/443 forwarding via Host Headers, process lifetime management and certificate management to name a few.

Here's what it looks like when you run your ASP.NET Core application behind an IIS Web front:

ASP.NET Core IIS Hosting

ASP.NET Core applications are standalone Console applications invoked through the dotnet runtime command. They are not loaded into an IIS worker process, but rather loaded through a native IIS module called AspNetCoreModule that executes the external Console application.

The AspNetCoreModule has to be installed on your server and is part of the ASP.NET Core Server Hosting Bundle.

Once you've installed the hosting bundle (or you install the .NET Core SDK on your Dev machine) the AspNetCoreModule is available in the IIS native module list:

The ASPNetCoreModule interfaces ASP.NET Core Console Applications

The AspNetCoreModule is a native IIS module that hooks into the IIS pipeline very early in the request cycle and immediately redirects all traffic to the backend ASP.NET Core application. All requests - even those mapped to top level Handlers like ASPX bypass the IIS pipeline and are forwarded to the ASP.NET Core process. This means you can't easily mix ASP.NET Core and other frameworks in the same Site/Virtual directory, which feels a bit like a step back given that you could easily mix frameworks before in IIS.

While the IIS Site/Virtual still needs an IIS Application Pool to run in, the Application Pool should be set to use No Managed Code. Since the App Pool acts merely as a proxy to forward requests, there's no need to have it instantiate a .NET runtime.

The AspNetCoreModule's job is to ensure that your application gets loaded when the first request comes in and that the process stays loaded if for some reason the application crashes. You essentially get the same behavior as classic ASP.NET applications that are managed by WAS (Windows Activation Service).

Once running, incoming Http requests are handled by this module and then routed to your ASP.NET Core application.

So, requests come in from the Web and int the kernel mode http.sys driver which routes into IIS on the primary port (80) or SSL port (443). The request is then forwarded to your ASP.NET Core application on the HTTP port configured for your application which is not port 80/443. In essence, IIS acts a reverse proxy simply forwarding requests to your ASP.NET Core Web running the Kestrel Web server on a different port.

Kestrel picks up the request and pushes it into the ASP.NET Core middleware pipeline which then handles your request and passes it on to your application logic. The resulting HTTP output is then passed back to IIS which then pushes it back out over the Internet to the HTTP client that initiated the request - a browser, mobile client or application.

The AspNetCoreModule is configured via the web.config file found in the application's root, which points a the startup command (dotnet) and argument (your application's main dll) which are used to launch the .NET Core application. The configuration in the web.config file points the module at your application's root folder and the startup DLL that needs to be launched.

Here's what the web.config looks like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!--
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
  -->
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*"
        modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet"
                arguments=".\AlbumViewerNetCore.dll" 
                stdoutLogEnabled="false" 
                stdoutLogFile=".\logs\stdout" 
                forwardWindowsAuthToken="false" />
  </system.webServer>
</configuration>

You can see that module references dotnetexe and the compiled entry point DLL that holds your Main method in your .NET Core application.

You can also provide an optional section for Environment Variables if you were explicitly configuring various configuration startup environment settings.

<aspNetCore processPath="dotnet"
                arguments=".\AlbumViewerNetCore.dll" 
                stdoutLogEnabled="false" 
                stdoutLogFile=".\logs\stdout" 
                forwardWindowsAuthToken="false">
    <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
        
    </environmentVariables>
</aspNetCore>    

Note that you should use these settings sparingly and rather rely on the configuration settings object which gives you more control. Limit environment variable settings for specific startup options you need to configure the global environment. Otherwise stick to configuration file settings - or on Azure use the application settings to merge values into your config.

Do you need IIS?

We've already discussed that when running ASP.NET Core on Windows, it's recommended you use IIS as a front end proxy. While it's possible to directly access Kestrel via an IP Address and available port, there are number of reasons why you don't want to expose your application directly this way in production environments.

First and foremost, if you want to have multiple applications running on a single server that all share port 80 and port 443 you can't run Kestrel directly. Kestrel doesn't support host header routing which is required to allow multiple port 80 bindings on a single IP address. Without IIS (or http.sys actually) you currently can't do this using Kestrel alone (and I think this is not planned either).

The AspNetCoreModule running through IIS also provides the necessary process management to ensure that your application gets loaded on the first access, ensures that it stays up and running and is restarted if it crashes. The AspNetCoreModule provides the required process management to ensure that your AspNetCore application is always available even after a crash.

It's also a good idea to run secure SSL requests through IIS proper by setting up certificates through the IIS certificate store and letting IIS handle the SSL authentication. The backplane HTTP request from IIS can then simply fire a non-secure HTTP request to your application. This means only a the front end IIS server needs a certificate even if you have multiple servers on the backplane serving the actual HTTP content.

IIS can also provide static file serving, gzip compression of static content, static file caching, Url Rewriting and a host of other features that IIS provides natively. IIS is really good and efficient at processing non-application requests, so it's worthwhile to take advantage of that. You can let IIS handle the tasks that it's really good at, and leave the dynamic tasks to pass through to your ASP.NET Core application.

The bottom line for all of this is if you are hosting on Windows you'll want to use IIS and the AspNetCoreModule.

Running IIS as a Development Server - no

So I've seen this question comes up occasionally:

Can I run full IIS to run and debug my ASP.NET Core Applications like I could with classic applications?

To sidestep this question a little: There should be very few reasons for you to run IIS during development. Yes, in the past there were very good reasons to run full IIS because there were always a number of things that behaved very differently in full IIS compared to IIS Express.

However, with ASP.NET Core there's little to no reason to be running full IIS during development. Why? Because ASP.NET Core applications aren't actually running inside of IIS. Whether you running called from IIS, IIS Express or whether you do dotnet run directly from the command line - you are running the exact same code and in most cases the exact same execution environment. Running inside of IIS really doesn't buy you anything anymore that you can't easily simulate with a command line environment.

The only reason you might need to run under IIS if there is something that IIS provides in terms of HTTP services that is really separate from the ASP.NET Core processing. But even then it's likely that those features won't be something you need to debug in the context of your application.

'Running' IIS

The reason that you can't 'just run IIS' from your development environment is that an ASP.NET Core application has to be published before it can be executed. The development folder doesn't hold all the files necessary to run your application. When you 'debug' or 'run' your application the application is first published to a separate location and run from there. For this reason you don't see IIS as an option in Visual Studio for example.

If you absolutely have to run with IIS, you can publish the application to a local folder first, then configure an IIS virtual directory or site and use that to run your site.

Publishing ASP.NET Core Applications for IIS

In order to run an application with IIS you have to first publish it. There are two ways to that you can do this today:

  • Use dotnet publish
  • Use the Visual Studio Publishing Features

Using dotnet publish

Using dotnet publish builds your application and copies a runnable, self-contained version of the project to a new location on disk. You specify an output folder where all the files are published. This is not so different from classic ASP.NET which ran Web sites out of temp folders. With ASP.NET Core you explicitly publish an application into a location of your choice - the files are no longer hidden away and magically copied around.

A typical publish command may look like this:

dotnet publish
      --framework netcoreapp1.0 
      --output "c:\temp\AlbumViewerWeb" 
      --configuration Release

This publishes the application to the c:\temp\albumviewerWeb.

If you open this folder you'll find that it contains your original application structure plus all the nuget dependency assemblies dumped into the root folder:

Manual IIS Hosting of a Publish Folder

Once you've published your application and you've moved it to your server (via FTP or other mechanism) we can then hook up IIS to the folder.

I'm going to create a virtual Application directory:

Note that I created an AspNetCore Application Pool that has its .NET Runtime set to No Managed Code as shown earlier.

IIS Identity and Permissions

You might also have to tweak the IIS App Pool Identity to something other than the default ApplicationPoolIdentity in order to ensure that your application has access to resources it needs to run. I generally start with NETWORKSERVICE and then move to a custom account that matches the actual rights required by the application.

And that's really all that needs to happen. You should be able to now navigate to your site or Virtual and the application just runs.

You can now take this locally deployed Web site, copy it to a Web Server (via FTP or direct file copy or other publishing solution), set up a Site or Virtual and you are off to the races.

Publishing from Visual Studio

The dotnet publish step works to copy the entire project to a folder, but it doesn't actually publish your project to a Web site (currently - this is likely coming at a later point).

In order to get incremental publishing to work, which is really quite crucial for ASP.NET Core applications because there are so many dependencies, you need to use MsDeploy which is available as part of Visual Studio's Web Publishing features.

Currently the Visual Studio Tooling UI is very incomplete, but the underlying functionality is supported. I'll point out a few tweaks that you can use to get this to work today.

When you go into Visual Studio in the RC2 Web tooling and the Publish dialog, you'll find that you can't create a publish profile that points at IIS. There are options for file and Azure publishing but there's no way through the UI to create a new Web site publish.

However, you can cheat by creating your own .pubxml file and putting it into the \Properties\PublishProfiles folder in your project.

Version Specific Workaround

Note it's almost certain this will get fixed post RC2 with a tooling update, so before you go through these steps if you read this article a month from now, check whether you can create an IIS publish profile directly through the Visual Studio UI.

To create a 'manual profile' in your ASP.NET Core Web project:

  • Create a folder \Properties\PublishProfiles
  • Create a file <MyProfile>.pubxml

You can copy an existing .pubxml from a non-ASP.NET Core project or create one. Here's an example of a profile that works with IIS:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>http://samples.west-wind.com/AlbumViewerCore/index.html</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <PublishFramework>netcoreapp1.0</PublishFramework>
    <UsePowerShell>True</UsePowerShell>
    <EnableMSDeployAppOffline>True</EnableMSDeployAppOffline>
    <MSDeployServiceURL>https://publish.west-wind.com</MSDeployServiceURL>
    <DeployIisAppPath>samples site/albumviewercore</DeployIisAppPath>
    <RemoteSitePhysicalPath />
    <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>RemoteAgent</MSDeployPublishMethod>
    <EnableMSDeployBackup>False</EnableMSDeployBackup>
    <UserName>username</UserName>
    <_SavePWD>True</_SavePWD>
    <ADUsesOwinOrOpenIdConnect>False</ADUsesOwinOrOpenIdConnect>
    <AuthType>NTLM</AuthType>
  </PropertyGroup>
</Project>

AuthType NTLM Fix

Note the <AuthType>NTLM</AuthType> key at the bottom of the file. This key is very important or else the publish operation doesn't work. If you're copying from an existing file make sure you add this key as it's unlikely to have it by default.

Once you've created a .pubxml file you can now open the publish dialog in Visual Studio with this Profile selected:

At this point you should be able to publish your site to IIS on a remote server and use incremental updates with your content.

And it's a Wrap

Currently IIS hosting and publishing is not particularly well documented and there are some rough edges around the publishing process. Microsoft knows of these issues and this will get fixed by RTM of ASP.NET Core.

In the meantime I hope this post has provided the information you need to understand how IIS hosting works and a few tweaks that let you use the publishing tools available to get your IIS applications running on your Windows Server.

Rock on...

More

I created another couple of posts that follow up this one with a few more specific use cases: Process Identity, Performance and using IIS to serve static content:

this post created with Markdown Monster
Posted in ASP.NET  ASP.NET  

The Voices of Reason


 

Marcin
June 06, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Great explanation of the things behind IIS + ASP.NET Core, thanks!

Mort
June 06, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Thanks, that was a pretty good article. Well written and clearly understandable and useful.

Alex Sarafian
June 07, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Excellent article and thank you for the effort.
One small remark though.
As far as I know, you get one W3WP.exe process per application pool. If the pool is shared between multiple websites or web applications then you get one process.

Having said that, the new pipeline is not that different after all.
The application pool acted as a process template and as with all new modern stuff, your application fully owns the process.

What was not 100% clear for me is whether IIS as reverse proxy does SSL offloading also? And if yes, then does it have to?

Michael
June 07, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

So how or where do I add URL rewrite? I'm having problems with my angular app using the html5mode

Tyler
June 07, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Rick, this is a great article. I want to find a parallel article to being able to use Apache as the reverse proxy on Linux.

Fred Peters
June 07, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Thanks Rick for this information. Our group's architect has spent two weeks trying to get our large application updated to RC2. Getting the app to run under IIS in our User Acceptance server has been tedious.

So I assume somewhere back up the line IIS Express was fitted with its version of the AspNetCoreModule.

rtur
June 07, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

I wish I have this guide few weeks back when I was banging my head against the wall. Still learned few tricks, thanks for sharing. Maybe NTLM bit will fix my Azure profile crashing VS, have to try it out.

Rick Strahl
June 07, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

@Michael - re: UrlRewrite, that's a good question. As far as I can see AspNetCoreModule bypasses the entire IIS Pipeline including UrlRewrite. I'm trying to find out more and do a follow up article on some of the implications of running with IIS this way. For now it seems it's an all or nothing aproach - you need to let Kestrel do all the Web server functionality including internal app routing. The alternative is to have a root site that uses standard IIS, and a virtual that runs the AspNetCore app which would allow you to separate out the features.

@Tyler - I don't know about how to set up Apache, but the more common scenario is using nginx on Linux. This topic covers nginx in the ASP.NET documentation: https://docs.asp.net/en/latest/publishing/linuxproduction.html?highlight=nginx

@Alex - Application Pools WERE the process in classic ASP.NET. In ASP.NET Core you have both the Application Pool process AND the AspNetCore process active. Since the Application Pool just acts as a proxy it's not going to be super resource intensive, so you can probably host all your ASP.NET Core apps through a single Application Pool/Proxy which is the scenario shown in the figure.

hashname
June 09, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Thank you Rick. I wish .Net Core team would publish articles which lays things out as clearly as you do. :)

Rick Strahl
June 09, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

@hashname - Thank you for the kind words. But credit where credit is due - the new ASP.NET docs (and also the .NET Core docs) are actually very good. Maybe not in high level topics, but for the nuts and bolt stuff I've been very impressed with the quality of the actual platform docs. Especially when you compare to the hell that is MSDN documentation.

TJ
June 15, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Unfortunately, publishing ASP.NET Core 1.0 RC2 Web sites to a remote IIS server as non-administrator still does not work in Visual Studio 2015. Due to this, preview and publish fails if the user account set in the publishing profile is not a member of the Administrators group on the remote server.

However, it is possible to resolve both issues as shown below.

Workaround for the Publish-ASP.NET_Core_1.0_RC2-application-to-IIS-as-non-administrator-fails issue:

1) Back up C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\1.1.0\publish-module.psm1

2) Open C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\1.1.0\publish-module.psm1

3) Go to line 694

4) Replace

(InternalNormalize-MSDeployUrl -serviceUrl $publishProperties['MSDeployServiceURL'] -serviceMethod $serviceMethod),

with

(InternalNormalize-MSDeployUrl -serviceUrl ($publishProperties['MSDeployServiceURL'] + '/msdeploy.axd?site=' + $publishProperties['DeployIisAppPath'].Split('/')[0]) -serviceMethod $serviceMethod),

Note: Do the same for C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Powershell\1.1.0\publish-module.psm1 as you see fit.


Workaround for the Publish-ASP.NET_Core_1.0_RC2-application-to-IIS-as-non-administrator-Preview-fails issue:

1) Back up C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets

2) Open C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets

3) Go to line 248

4) Replace

<ComputerName>$(MsDeployServiceUrl)</ComputerName>

with

<ComputerName>$(MsDeployServiceUrl)?site=$(DeployIisAppPath.Split('/')[0])</ComputerName>


Now, you should be able to import your Web publishing profile (i.e. example.com.publishsettings) and preview/publish without issues.

Publishing Profile Example (Site):

<?xml version="1.0" encoding="utf-8"?>
<publishData>
<publishProfile
profileName="example.com - Web Deploy"
publishMethod="MSDeploy"
publishUrl="remote.server:8172"
msdeploySite="example.com"
userName="examplecom_pub"
userPWD="PASSWORD_HERE"
destinationAppUrl="http://example.com/"
/>
</publishData>

Publishing Profile Example (Site/Application):

<?xml version="1.0" encoding="utf-8"?>
<publishData>
<publishProfile
profileName="example.com - application - Web Deploy"
publishMethod="MSDeploy"
publishUrl="remote.server:8172"
msdeploySite="example.com/application"
userName="examplecompub"
userPWD="PASSWORD_HERE"
destinationAppUrl="http://example.com/application"
/>
</publishData>


Note: The 'approot' folder no longer exists in RC2, Web Deploy permissions are only required to be set on the 'wwwroot' folder (like it was in the past...)!

Dan Kellett
July 08, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

This was extremely helpful. Thank you.

Felix
July 10, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Thank you - this article puts together many things that we guessed using "trial and error". There are still several things that are puzzling. As somebody mentioned, WebDAV publishing to the server isn't yet available, and simply publish to local directory and copy to remote server doesn't work because many DLLs are locked. So, one needs to stop the site, then copy files, then start again. A few other idiosyncrasies like that.

However, the biggest problem that I can't find any guidance is virtual directory support (not app in virtual directory, but virtual directory inside the app). We had a pointer to UNC path that contained picture gallery. Short of moving gigabytes of data to IIS server, I can't figure out how to do that...

If anybody knows some post that explains it - I would greatly appreciate the pointer

Mike Hillman
July 11, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Thanks. You have a gift for explaining the technical.

Ted
July 12, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Thanks Rick. Great Article (as are many of your other posts)!

Do you know if it is possible to host two web sites on IIS (on the same server) and have the ASP.NET core site use a port other than 80? I have two web sites one asp.net 5 and one .net core and if I switch the asp.net 5 site to a different port (8080) and use port 80 for the .net core site both sites work fine. If I use port 8080 for the .net core site (and 80 for the asp.net 5 site) when I browse to the .net core site I get an error that "The site cannot be reached".

Jandler Mayer
August 04, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Hello Rick,

Thanks for the article. It was very informative on the inner working on IIS.

I followed it to deploy my very basic site created by following the two links (https://docs.asp.net/en/latest/getting-started.html, https://docs.asp.net/en/latest/publishing/iis.html) but I ran into a prickle.

It seems when I set my application pool to No Managed Code / Integrated, I keep getting

"HTTP Error 500.24 - Internal Server Error

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode."

If I change it to .NET 4 / Integrated, it works.
If I change it to No Managed/Classic, it works also.

Do you have an idea on how to debug this situation? I do see the dotnet.exe running my dll.

Rick Strahl
August 04, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

@Jandle - either you have an ASP.NET setting in your Web.config for the application, or - more likely - you're using a virtual directory and that virtual is inheriting settings from the parent site. You might try this again with a top level site and see if that changes the behavior.

Jandler
August 04, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

@Rick

I deployed my app inside a new web site right under the "sites" folder in IIS. There is no virtual folder and as far as I can tell there is no parent site.

My web.config is actually quite simple

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\aspnetcoreapp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>


What's weird is that I just tried the same setup on another machine and it works.

Brian Edwards
August 18, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Hi Rick,

This is great. My web site when created had "emitEntryPoint": true in build options and was creating an .Exe by default. When I deployed it to IIS it worked fine. I wanted to change it to a DLL so I don't have to recycle the app pool every time I publish. I made the changes to web.config to processPath="dotnet" arguments="websitename.dll" (previously processPath was the .exe and arguments was empty). But now I get HTTP Error 502.5 - Process Failure and in the event log it just has:
Failed to start process with commandline '"dotnet" websitename.dll', ErrorCode = '0x80004005'.

Any other steps you are aware of to fix that, it seems Visual Studio defaults has emitEntryPoint: true when it creates a web site.

Thanks!

Brian Edwards

jdan
August 19, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

I just spent hours/days trying to work with this and the asp.net docs (which I don't think are anywhere near as good as you suggest, but there you go), cursing all the while, wondering why this didn't work when I realized I was under a slightly different scenario:

I am creating an ASP.NET core app, but have to 'target' (not sure that's the right terminology here) net461 as the framework.

This creates an exe, not a dll, just for one obvious difference, but ultimately, the main difference is that I just don't think this scenario works yet. I can get a site deployed locally, but it just doesn't work (stdout tells me there's something running at a local port that is being fronted by IIS) but the site doesn't produce any output. No errors, just doesn't work.

BTW, I completely disagree about not being able to run under IIS for development. There are SO many differences running under IIS Express, the very least of which is, say, trying to browse from another machine to your dev box to test different scenarios (like, say, hitting it with a real mobile device instead of emulation). But that's another topic.

Rick Strahl
August 21, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

@Brian - Yeah the post was originally written for RC2 and then updated for RTM so I think the emitEntryPoint setting got added to the default template properly.

@jdan - Yes I haven't tried targeting net461 so not sure how that would work, although that's definitely a scenario that should work. Personally I think if you are targetting 461 you're better off just creating a standard ASP.NET app rather than a core app, but regardless this should work. I can't check this right now as I'm out travelling, but maybe somebody else can confirm that they got running net461 working under IIS.

Re: IIS Express - you can enable remote access with IIS Express by opening up the ports you can use 'netsh add urlacl url=http://*:23434/ user=username listen=yes'. Not automatic for sure, but it works.

jdan
August 22, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Rick:

I totally agree it should work.

I'm guessing my scenario is one that is going to be pretty common. I have a dependency that cannot as of yet be recompiled under .NET Core, so I have an otherwise 'pure' Asp.NET Core using all its shiny new features, but I have to target 461 until the dependency can be updated.

Trying various build options to see if that works.....

Scott Addie
August 22, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

@Rick - I'm looking to do the same thing as @jdan, mostly because my client isn't ready for .NET Core yet. The only difference is that this will be deployed either on-prem or in Azure. Any reasons in particular why you'd recommend sticking with standard ASP.NET when targeting .NET Framework? Just want to make sure there's not something I'm unaware of before I go too far down the "ASP.NET Core with .NET Framework" path.

jdan
August 23, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Thank goodness, it was a Pebkac issue.

At some point, they went from publishOptions exclude to publishOptions include, and I horked it up.

Once I figured out that it was serving static files, it became easier to track down.

Whew. I am always satisfied when it is idiot developer issue and not something more serious.

Saf
September 25, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

After following you article I'm getting blank page when I run the app as localhost/myPublishedFolder. What I may be missing? I've VS2015 and ASP.NET Core 1.0 on Windows 10. This is an ASP.NET MVC Core app on local machine.

Mike Wang
September 28, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

There is not a single mention of the version of IIS that works with ASP.NET CORE.

On the DOD mil sites we still are on Windows 2008 R2 with IIS 7 and 7.7.

So anyone, Can ASP.NET CORE be deployed on IIS 7?

Rick Strahl
September 28, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

@Mike - it works with Windows 2008 R2. I am not sure about original Server 2008 though. You're right though - there are no requirements posted that I could find in a casual search.

Gina
October 07, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Great article Rick!
If anyone can answer this, it would be you- or anyone else reading your article.

I have successfully deployed an asp net core app, utilizing IIS 7.5 and I need to run a sub application (ver 4.6) under it.. accessing it with the domain.com/newapp/. I have the asp net core app with an app pool "No managed code" (works fine), and I pointed to a different app pool for the sub application "v4.0 Integrated" - but, it won't run "HTTP Error 502.5 - Process Failure".

I can't find anywhere explaining how to do this.

Any help appreciated! Thanks!

Rick Strahl
October 07, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

@Gina - I'm not sure if that will work because the parent web.config will determine features in the sub folder. You can **try** removing the AspNetCoreModule explicitly from the module list in the subfolders and see if that might work.

buehler
October 10, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

If you're publishing to say the E:/ and you have installed the .NET Core Windows Server Hosting package (which will install the dotnet.exe on C:/) will this cause 500.19? When I publish and in IIS 7.5 I give the AppPoolIdentity rights to the directory, it is continuing to throw the 500.19 error, but all the way down to the C:/temp/Microsoft.Net/Frameworks64/2.0876483 directory. Which is making no sense at all!!! Please help! I developed the WebAPI on my Mac and followed all instructions to the letter, yet, I still cannot get past the 500.19 error. If I perform the "dotnet run" from the root directory via console, then navigate to http://localhost:5000/swagger/ui it looks beautiful.....else if I attempt to navigate to the url set in the host header (https://api.mysite.com:443) it throws the 500.19 error detailed above. Thank you for any assistance in advance!!!!

Ruard van Elburg
October 19, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

I've managed to publish a website on Windows 7, IIS 7.5. Only problem I've encountered during publishing was that I had to install PowerShell 3. It runs without problems, but I've noticed one thing: when I request a page the first time it takes about 10 seconds to load (for each page). Is there a way to speed this up?

Since it takes so long to load a page the first time, I do not want IIS to set the site to Idle after the specified timeout. I can prevent this by setting 'Idle timeout' (and Recycle) to zero in the advanced settings of the Application Pool. This 'fixes' the long loading time problem. But I wonder, what is best practice? Is it a task anyway of IIS to recycle or set the website to Idle?

Rick Strahl
October 22, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

@Ruard - 10 seconds for the first hit on the site seems about right, but only for the first page - not for each new page. There might be somehting else going on.

As to application timeouts - if you're running a dedicated site on your in house servers and you know you have enough resources to run your site(s), there's no reason to idle the site. But if you're running a lot of sites then idling can free up some memory for sites that are busy. Any site that's reasonably busy and public facing probably never goes idle anyway. Either way you can control this via the AppPool settings in IIS.

+++ Rick ---

Pranay
October 25, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

I am unable to access the web application on other machine in my network, but it runs successfully on my machine. Any idea what more i need to do to make it work on another machine ?

Rick Strahl
October 25, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

@Pranay - make sure the firewall allows your app to run over the port you are using.

Vik Shah
November 28, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

0 down vote I had a same issue . I changed application pool identity to network service account . Then I explicitly set the path to dotnet.exe in the web.config for the application to work properly as @danielyewright said in his github(https://github.com/aspnet/Hosting/issues/844) comment . It works after set the path.

Thanks


Brian
December 02, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Thanks for the great article Rick. I've just built my first Dot Net Core/Angular 2 app and then followed your guide here and my website opened on the first try! Awesome! Thanks again, Brian.


Paul Mason
December 15, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Having just deployed my first Core application, this article was most useful, thanks. I've encountered an issue with the routing if the Core application is loaded as an IIS application, such that the IIS application folder name gets missed out when I'm trying to redirect in code. So if my URL is https://mydomain/myapplicationname/identity/login and I try to redirect to https://mydomain/myapplicationname/home/index with an RedirectResult = "/home/index", what actually happens is that it redirects to https://mydomain/home/index, which raises an error. I've enquired in the asp.net forums about this and no-one seems to have a reasonable answer (the only suggestion has been this https://github.com/aspnet/IISIntegration/issues/14 which implies a fix, but never gets round to a clear conclusion). I've created a workaround by using a string saved as an appsetting. Or should we be creating Websites (which creates problems with having lots of port addresses being used up)?


ttm
December 19, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

One important question (at least for me): is this applicable only for Asp.Net Core application or it is the way to go for Asp.Net Core Application referencing v4.6.1 Framework?


John
December 29, 2016

# re: Publishing and Running ASP.NET Core Applications with IIS

Hi sailor! Even though I never mastered to carve while keep planing (I guess I never tried hard enough), your instruction to deploy worked perfectly. Thank you!


John Mark Isaac Madison
January 04, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

IIS and "dotnet run" are using two different execution environments I think. Juding by how running with IIS works, but "dotnet run" gets compilation errors.

Any tips on how to remedy?


Rick Strahl
January 05, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

@John - no they use different hosting environments. Code should work the same. dotnet run uses Kestrel by default, but you can change what it runs using either the configuration settings mentioned in this post: https://weblog.west-wind.com/posts/2016/Sep/28/External-Network-Access-to-Kestrel-and-IIS-Express-in-ASPNET-Core


pran
January 11, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

superb explanation of the inner workings of Core with IIS. Do you plan to update this article for the latest version of Asp.Net Core?


Edgars
January 12, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Thanks for this article - very helpful. I have succesfully deployed my first ASP.NET Core API with IIS.

Maybe someone here can answer to my question. In previous ASP.NET Web API v2 it was possible to return Status Code pages from IIS. Actually this functionality worked by default without additional configuration. Is it possible to achieve same functionality with ASP.NET Core deployed on IIS? Respectively - return status code pages from IIS.


Shoaib
January 24, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hi,

I am trying to deploy my ASP.Net core web application on shared server but I am getting 500 error.I have tried everything I can.Do we need ASP.Net Core sdk to be installed on shared server for application to run.


wal
February 02, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Rick, is it possible for IIS just to proxy the requests to the dotnet-core app and not manage its lifetime? the reason for asking is that I have an application with threads that I want to run as a windows service (that also listens for requests from IIS on port 5000). When i run my dotnet-core app as a service IIS simply ignores it and spawns another process for my dotnet-core. What i want AspNetCoreModule to do is go 'oh its already running and i speak to it on port x'


Rick Strahl
February 03, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Not sure, but if that's what you want to do you really just want a true reverse proxy. Maybe look into nginx on Windows to just do straight up proxy forwarding.


Wal
February 03, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Rick it appears a 'normal' reverse proxy in IIS is straight-forward. I used this article1 and got it working. stoked! So for anyone else who chances upon this you set up an empty website in IIS that uses URL Rewrite to forward everything to your dotnet-core app running as a windows service which listens on localhost only.


Web API call does not work on IIS Net.Core Angular 2 (works fine under IIS Express), got 404 error!
February 03, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

I got this error when calling the Wep API from Angular 2 client:

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:80/api/SampleData/AuditLogTableName/?tableName=CENTITYNAME

This is the code:

constructor(private http: Http, private pagerService: PagerService) {
            var res =  this.http.get('/api/SampleData/NTLogTableName/?tableName=' +'CTBL_NAME')
            .subscribe(result => {
                this.tableNames = result.json();
                this.tableNameStr = this.tableNames[0];
                this.onTableNameChange(this.tableNameStr);

    });

This is the Controller: [Route("api/[controller]")] public class SampleDataController : Controller {

    [HttpGet("[action]")]

    public async Task<List<string>> NTLogTableName(string tableName)
    {

}

It works fine in IIS Express!

(BTW I tried combination of '/api' './api' 'api' without any luck)

Thanks much!

Reinhard Sual


Alex
March 08, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Just wondering did not you notice following - while running from behind IIS dotnet core app loose ability to read machine level environment variables, but if run it as dotnet app.dll all works as expected


Rick Strahl
March 08, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

@Alex - The ASP.NET Core Module will launch Kestrel in the same user context as the IIS Application Pool the IIS app was started in, so the Kestrel process will inherit those writes and that environment. You may want to experiment with the user account in use - if you use the default is an super low rights Application Pool user and that may not have access to any machine environment whatsoever.


James A
March 13, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hey, as always, great post. Very thorough.

Question. Working in a big enterprise, we have to use Active Directory Domain identities and configure the IIS App Pools to run as those domain IDs in our environments, so that the apps can call across the network and connect to SQL Server. SQL Server will then also have the domain id registered as a valid login user. Not allowed to use passwords (even encrypted) in connection strings.

Even more fun, for our PROD environments, our security people are the only people allowed to log in to prod web servers and configure the App Pools to run as the domain identity. Only they have the passwords to the AD domain identities (stored in a password vault).

Will this setup be the same, connecting to SQL Server from a CORE app in Kestrel running behind IIS? If we have to go back to using connection strings with passwords, I will have a hard time selling that to the IT and Info Sec folks.


Rick Strahl
March 13, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

@James - Kestrel inherits the execution context from the IIS Application Pool you configure, so things should continue to work the way they worked when running classic ASP.NET applications. As long as you got a proper account setup for this it should work fine using passthrough security from your application into SQL as long as you have a valid domain account. I'm working on a followup post that talks about some of the questions raised here. Should be out when I get some spare cycles.


Sam
March 26, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Since this article was published in June 6, 2016 and there has been a lot of changes to the .NET Core, is the information still relevant?


Rick Strahl
March 27, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

@Sam - yes. Everything mentioned here still applies and is still appropriate.


Deepak
April 12, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hi Rick, a small doubt, is there any way to publish on every build ?


Rick Strahl
April 12, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

You need build automation tools for that. But it's easy enough - dotnet publish will publish to a specified folder (or bin\Release\publish if not path is specified) and you can copy or push to server from there.


Desmond Mardle
April 16, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Thanks for this article I have spent a few hours yesterday trying to get my .net core 1.1 website to run on IIS without any luck. This morning I came across your article and it solved my problem straight away. My website is running on Joomla at present. I have been getting to grips with asp.net core the exercise was to convert the existing site to an asp.net core 1.1 which is very near completion. I will publish the new site when finished.

Thanks Desmond6 Mardle


Jatin
April 19, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Thanks a lot sir for sharing this information; I did search a lot to find solution to be able to Publish ASP.NET Core website using the Web Deploy but it kept failing due to error:

Invalid URI: The format of the URI could not be determined (Its still failing as i write this comment);

But the work around you did mention to Publish using dotnet publish did help me Publish the website; Followed by i was also able to deploy the website to IIS Server by following the steps you defined for the same! Thanks Again for your Hard Work that went in to creating this content; Really appreciate it!


Jatin Mahesh Arya
April 19, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

I encountered an error: "Invalid URI: The format of the URI could not be determined" while trying to Publish ASP.NET CORE website and Deploy it via the built in Web Deploy feature of **Visual Studio 2015 Community ** edition on **Windows 10 + IIS Server **; After going through your above described information, i was successfully able to:

  • Publish the website using dotnet publish
  • Deploy the website to IIS Server + Windows 10 (after overcoming few environment specific hurdles)

Note: The Publish and Deploy via Web Deploy option of visual studio still fails with the same error specified above (Given i did not implement AuthType NTLM Fix)BUT i was successfully able to Publish the website content when i changed publish method from Web Deploy to File System

Thanks for sharing this valuable information; Really appreciate it!


Vasily
April 19, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hello, thanks for the article! So I have been working on a Core website for a while now, but have been informed recently that it should be not a Core standalone application but a .net Framework one. I'll have to go a little backwards and redo the whole thing in non-core code. Is there a lot of huge differences from the IT perspective you think?


Luis Harvey Trina
May 16, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hello Rick - I've followed your guide and publishes ASP.NET Core applications on IIS. They works fine. Expept for a detail. The application that runs behind IIS returns Context.Request.Path as null. Do not happend in a development environment.

This breaks the applications with Localizatiion techniques.

I would like to ask you if there is a solution so that from IIS Context.Request.Path does not return null, or have an alternative.

Sample: @culture.Text

Behind IIS the parameter returnUrl is null -

Regards


Luis Harvey Trina
May 16, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hello Rick - I've followed your guide and publishes ASP.NET Core applications on IIS. They works fine. Expept for a detail. The application that runs behind IIS returns Context.Request.Path as null. Do not happend in a development environment. This breaks the applications with Localizatiion techniques.

I would like to ask you if there is a solution so that from IIS Context.Request.Path does not return null, or have an alternative.

Regards


Mark Entingh
July 13, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

I'd like to keep my development server running in IIS so I can access it at any time from a locally created domain name. I've set up a domain in my hosts file & set up IIS to run a .NET Core app, and I'm pretty sure I am able to attach a debugger to the kestrel process in Visual Studio. Haven't tested that yet, though. If I'm able to, then I could say that it is definitely a good option to host a .NET Core app in IIS on a dev machine with a custom domain name.


Riza
July 17, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hi Rick,

Can we deploy asp.net core, with fallback target 4.5.2 to Windows Server IIS as it is, without the need to install the Windows Server Hosting component first? Meaning, the application pool still uses .NET 4.0 Managed. I ask this question, because I have client requirement like this, as I'm not allow to touch the IIS nor server machine. They just gave me the wwwroot/[the app folder] access. If the app is just ASP.NET MVC classic using .NET 4.5.2, its okay.


frank
July 26, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hi,

am I able to run .net core 1.1.2+ and a asp.net 4.6 app side by side on a IIS 8.5? somehow i am not able to get it working.. getting

HTTP Error 500.21 - Internal Server Error
Handler "ExtensionlessUrlHandler-Integrated-4.0" has a bad module "ManagedPipelineHandler" in its module list

but app works when debuging from VS2015.. do you have an idea?


Rick Strahl
July 26, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Yes you can, but you have to make sure ASP.NET requests can be passed through to the 4.6 requests. By default all requests are routed to Kestrel.

More info here:

Frankly the better choice most likely is to create a separate site or virtual directory for your ASP.NET 4.6 app rather than trying to mix the two in a single application. it can be done but it's not as efficient as the .NET Core app can without even requiring the ASP.NET Runtime.

+++ Rick ---


frank
July 26, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hi Rick,

thanks for the quick answer. I have acutally a seperate site, but getting above error message. I have a site on IIS for the .net core app on port 80 and the classic asp.net Web API 2 running in a seperate Site on port 9000, but this seems not to work..


Matthew
August 17, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Rick,

Thanks for writing the very helpful article. I was wasting a bunch of time trying to figure out how to debug under IIS with dotnet core and now realize it's not necessary.

Matthew


Rick Strahl
August 17, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

@Matthew - Yup in most cases it's not necessary to run under IIS, but as of Visual Studio 2017.3 you can use IIS for debugging.


Martin
August 31, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

I'm using dotnet publish with the --configuration release switch to build my web app. It works great, but I can't seem to get my connection string in my appsettings.json file to transform into my appsettings.release.json file. Does this work?


Ratan
September 15, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hi Rick,

Great article, but I am stuck in this dilemma of having a sub application which is not a dot net core app.

I just updated my .net web application to .net core 2.0 which runs just fine. There is a sub-site which is a non-core web application. This sub-application throws an error now: "core 2.0 site error HTTP Error 502.5 - Process Failure."

I changed the application pool settings to no managed code and explicitly removed the handler for dotnetcore as well.

If I keep the .NET CLR version to old v4..., the sub application loads but then it can't find any of the css files or js files in the sub-application folder.

So I created a different application pool for the sub application with CLR version as v4, and now it loads. But it can't find any css files or js files. I am getting a status 502 (Bad Gateway) for all these files. For example:

AppA: Main .net core 2 web app SubAppB: .net 4.6 web app.

On going to https://www.AppA.com/SubAppB/Account/Login All the images, css, js files are throwing 502. In chrome, I see the the browser looking for the files at location: https://www.AppA.com/SubAppB/Content/login.css

BTW, I have set the main AppA's applicationpoolidenetity to NetworkService, but that did not help. How do I get it to find those files in the sub app?


Rick Strahl
September 15, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

@Ratan - this should work as long as you create the sub-application as a new Application (not virtual), and you create a new custom application pool. You also have to explicitly remove the ASP.NET Core Handler (remove name="aspNetCore" />). I'd suspect the 502 errors are something else - those are bad gateway errors usually associated with proxies or load balancing servers. There may be some other config settings leaking from somewhere else in your configuration chain.


Sujith Sethumadhavan
September 21, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hi Rick,

Great article. Is there any way I share the session between an ASP.Net application (Running on .Net 4.5 framework) and ASP.Net Core (Running on Core 2) application. Where ASP.Net Core Website is created under ASP.Net website as a Application.

Thanks in Advance. Sujith


Ratan
September 22, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

@Rick - I did the same. Created a new application inside the site and assigned it a separate application pool and also removed the handler. The application loads but it cannot find any of the static files.


Ratan
September 25, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

@Rick Wanted to point out that the sub-app works fine unless I add a php handler to the main site's config file to handle php requests. Aso soon as I add below, the sub-app cannot find the static contents.

<handlers>
            <clear />
            <add name="PHP54_via_FastCGI" path="*.php" verb="GET,HEAD,POST" type="" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v5.4\php-cgi.exe" resourceType="Either" requireAccess="Script" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
            <add name="aspNetCore" path="*" verb="*" type="" modules="AspNetCoreModule" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
           
    </handlers>

Kyle Denney
November 13, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hello,

I have an IIS ASP.Net Core 2 implementation setup which works fine over port 80. But the same codebase doesn't want to work with SSL and port 443. It returns a 404 given the same parameters as the port 80 site. Are there special considerations using IIS and port 443 to consider in the Program.cs or Startup.cs even if you are not securing Kestrel with SSL? Is there something else to consider other than Kestrel here? It seems like the documentation on getting SSL up and running with IIS as a reverse proxy needs further explanation and guidance.


flipdoubt
November 13, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Rick, have you written about updating an existing site using dotnet publish? Whenever I do this, the site's files are locked by the dotnet process serving the existing site. Does Kestrel have anything like app_offline.htm that would interrupt the site so it can be updated? Can you point to any existing docs or discussion of best practices around updating an existing site?

As always, thanks.


Rick Strahl
November 15, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

@Kyle - if you're using IIS in front of Kestrel you should just be able to add your certificate like you normally do in IIS. There's nothing special that has to be done. The requests are forwarded to Kestrel as plain (non-SSL requests) so that might have some effect if your code is checking for specific behavior - I believe the original URL info will be in the X- proxy forwarding headers.

FWIW, I run my sample app (https://albumviewer.west-wind.com) on IIS with a Lets Encrypt certificate, and there was nothing custom about making that work. Just install the cert to the site and off you go.

You might want to look closely on the IIS error message to see what the 404 is complaining about exactly and you can also look at the IIS request trace. Is it an IIS Error? Or is it coming from Kestrel?


Rick Strahl
November 15, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

@flipdoubt - if you're running using IIS AppOffline.htm should still work. If you use MSDEPLOY or WebPublish the using a <EnableMSDeployAppOffline>True</EnableMSDeployAppOffline> in your publish profile should do the trick in automatically doing this. I haven't tried this recently but this was working a while back. Note - the element is not in the publish file by default, so you have to manually add it in the .pubxml file.


Maris Kurens
November 26, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Like your article The .pubxml file has elements for which we can't find any explanatory documentation. We're not sure where to set the pointers to : Does using MSDeploy still retain the FileSystem tag if we're publishing from the File System ? We don't see the DeployIisAppPath tag in your sample but we have in other previous Web Service project .pubxml files generated by MVC 3. Wrt to IIS Virtual app, do we define it as an Add Virtual Directory or Add Application ? Is Application Pool Pipeline mode Integrated or Classic ? In the VS project application settings we are using Windows output type, is that correct ? We employ C# ado.net connections to SQL Server (2016) how do we integrate that ? In short is there any resource that we can tap that maps out if not all but some of workable scenarios.


Ravi Kumar Suresh Babu
December 01, 2017

# re: Publishing and Running ASP.NET Core Applications with IIS

Hi Rick. I have deployed my asp net core 2 app on IIS. I am not able to see the certificates sent by the clients in https handler in aps net core app. I think I might be missing a configuration in IIS to pass the certificate to asp net core app. I have configured IIS to allow/require certificate. I have configured kestrel to allow client certificates. Can you help me with the pointers on what else could I be missing ?


Neutrino
January 19, 2018

# re: Publishing and Running ASP.NET Core Applications with IIS

Publish in VS2017 appears to be completely non-functional.

I have an ASP.Net Core web service. This web service has a native dependency that is copied to the output directory via a Copy statement in the .csproj file as an AfterCompile step.

Running the release or debug build everything works fine. If I Publish though none of the native dependencies that the project file has copied to the output directory end up in the publish directory.

Getting a complete deployable build therefore becomes a process of running Publish and then manually doctoring the Publish directory by adding to it all the project output that the Publish command unhelpfully decided to completely ignore.

So does anyone know of any way to get VS2017 to perform a correctly functioning publish of anything more complex than a 'hello world' application?


Raimund Popp
April 17, 2018

# re: Publishing and Running ASP.NET Core Applications with IIS

this is the great and only article explaining all the trouble, when someone tries to publish a asp core application. so far i a really p.. by developing asp mvc core 2, because all the difficult work which is done fails when developers try to go online. there are no comments or help stuff on mvc core sites. All what i could find is the former framework errors, and asp errors. couldn't the ms-guys write the trouble for iis write somewhere down as simple examples? so far: thanks for your explanations and: i am really disappointed on ms, leaving the developers in the darkness of finding out solutions for themself... days later.


Eduard Riera
December 08, 2018

# re: Publishing and Running ASP.NET Core Applications with IIS

Kestrel doesn't use http.sys kernel driver. Is there a concept of port reservation in Kestrel? What happens if http.sys and kestrel tries to use the same port? If http.sys already have the reservation (even if nothing is currently listening) kestrel cannot use the port?


Rick Strahl
December 09, 2018

# re: Publishing and Running ASP.NET Core Applications with IIS

@Eduard - correct. Kestrel requires exclusive access to a port in order to work. If the port is already in use Kestrel will fail to launch, and http.sys won't be able to reserve a port if kestrel is already using a port.


Alex
December 29, 2018

# re: Publishing and Running ASP.NET Core Applications with IIS

Thanks for a plain english explanation, really. "IIS acts as a reverse proxy" - why has no one said it before?

PS. Even though we're still trying to figure out the big question - should one move to ASP.NET Core at all if he runs on Windows/IIS?


Rick Strahl
December 31, 2018

# re: Publishing and Running ASP.NET Core Applications with IIS

@Alex - to confuse things a little more, ASP.NET Core 2.2 by default now uses InProcess hosting in IIS with its own .NET Core Module that loads the runtime without the external dotnet.exe. This is closer to the old .NET runtime hosting in IIS and should improve throughput significantly - the old proxy way also still works so it'll be easy to compare performance.


Alex
January 15, 2019

# re: Publishing and Running ASP.NET Core Applications with IIS

Thanks! That's good news actually. Found the fresh tutorial here: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.2


Sven Vranckx
February 10, 2019

# re: Publishing and Running ASP.NET Core Applications with IIS

Excellent tutorial, but you may want to update the AspNetCoreModule link to point to the latest release: https://docs.microsoft.com/nl-nl/aspnet/core/host-and-deploy/iis/index?view=aspnetcore-2.2#install-the-net-core-hosting-bundle (the link in the article still points to a release candidate)

Thanks!


Rick Strahl
February 11, 2019

# re: Publishing and Running ASP.NET Core Applications with IIS

@Sven - working on another post that's mostly done for the new InProcess hosting model. Hopefully will be out in the next week or so.


BD9000
June 09, 2019

# re: Publishing and Running ASP.NET Core Applications with IIS

Any way this can be updated for Dotnet Core 2.2? It appears configuring Windows Server 2012 (IIS8.0) with Dotnet Core 2.2 is an exercise in madness (lots of posts everywhere including StackExchange, MSDN, and no solutions).


Rick Strahl
June 10, 2019

# re: Publishing and Running ASP.NET Core Applications with IIS

@BD9000 - All that is described in this article still applies in .NET Core 2.2 and later. The additional functionality is InProcess hosting which is linked at the top and bottom of this article with a follow up post.


Drew Berkemeyer
August 16, 2019

# re: Publishing and Running ASP.NET Core Applications with IIS

Thank you Rick! This article was a HUGE help. You confirmed several things I had suspected. The detailed explanation is really appreciated.


Salvi
September 30, 2019

# re: Publishing and Running ASP.NET Core Applications with IIS

Thanks for breaking this down and making it easy to understand! Thanks also for the many useful articles your publish here. Your work is tremendous and it simplifies it for us to digest the materials. Kudos to you!


Tharn Jaggar
October 15, 2019

# re: Publishing and Running ASP.NET Core Applications with IIS

Nice article, as always. I have a specific problem not covered here, nor in other articles I could find: We are developing a new ASP.NETCore app, and we need to deploy that one on a server running a very large legacy site in ASP.Net2.0 Our idea was to deploy the new .NETCore app as applications under some /newapp application path. However doing so fails to run the ASP.NETCore app because of web.config in the root that applies also to it... Is there a way to make the app completely independant from the root site so that it can run just like if it was standalone ?


Rick Strahl
October 15, 2019

# re: Publishing and Running ASP.NET Core Applications with IIS

@Tharn - you can use <location> tags to isolate the settings reasonably well, but my guess is you'll have to explicitly remove all the keys that are problematic at the server root with <remove> attributes where possible.


Tyler Andreasen
August 05, 2020

# re: Publishing and Running ASP.NET Core Applications with IIS

I have a simple (and maybe stupid) question: I have an IIS site running a ASP.NET Core 3.1 website. If I install the latest version of the SDK on the machine that deploys the DLLs, is it safe to say that the site will use the DLLs deployed from the publishing machine? Or, is it necessary to have the SDK also installed on the machine where the website is being hosted? I believe it to be the latter (without the SDK installed, the website will not function on the host machine) - and it's very difficult to tell what the exact version is that will be used by a website on a machine that has multiple versions of the SDK installed.


Chris
October 21, 2020

# re: Publishing and Running ASP.NET Core Applications with IIS

Great article Rick.

You say "There should be very few reasons for you to run IIS during development" which I understand based on you reasoning however it appears that AJAX requests are all but impossible with .Net Core when you have Windows Authentication enabled due to the fact that CORS OPTIONS pre-flight requests do not have the necessary authentication token to allow the request to actually reach the Kestrel server and therefore the .Net Core website.

The only suggested solution to this is to use the IIS CORS Module but this then requires you to run the site through IIS. I've not yet managed to successfully run a project through IIS and make use of the CORS Module so my only options are to constantly publish and test or make do without AJAX. It's almost as if the Kestrel server is implementing just enough functionality to block the OPTIONS requests but not enough functionality to get around this as you would be able to in a live environment.

I'd love to know if you have an alternative solution to this.


Rick Strahl
October 21, 2020

# re: Publishing and Running ASP.NET Core Applications with IIS

@Chris - that's not right. I have built a couple of applications that use Windows Authentication running IIS, IIS Express and the local Kestrel server. The apps are SPA style apps and are using APIs for data retrieval on separate sites set with CORS. It works fine.

Getting Windows Authentication working is another story - that's a pain in the ass especially in Kestrel, but you can find more info on that in a couple of related posts (and another here).


Sjoerd
January 05, 2021

# re: Publishing and Running ASP.NET Core Applications with IIS

Hi Rick,

Great article.

About your comment: "move to a custom account that matches the actual rights required by the application".

I'm searching for the least amount of privileges needed for an specific account to run an asp.net core 2.1 application. However i can't seem to find information about this. Any links/suggestions?


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024