Hosting DotNet Core Web Application on Windows Server (IIS8)

So finally I get around to this.. Sorry to keep anyone waiting but when life knocks at the door well you simply have to answer it. (It’s like that uninvited guest that comes to your house when you have the lights on and you just hope that you can pretend you aren’t at home resulting in them leaving without question hahah \(^_^)/ yay!! )

Let’s get to it! So if you are a true programmer all your tooling will be requiring massive updates because we only stay elite when bashing our heads on the desk solving issues that have already been solved right!! Correct!!  (-_-)

So if you haven’t already kept up with the latest tech get Visual Studio updated with the latest tooling. There is no shame in being elite at being behind.

microsoft_tooling

Check out the available updates at http://getdotnet.azurewebsites.net/target-dotnet-platforms.html

So I’m assuming that we all know how the process for creating a new web application within Visual Studio if you are reading this post. If not I have linked this to some other awesome blog post. https://jonhilton.net/2016/10/19/creating-a-new-net-core-web-application-what-are-your-options

Some new selections will be the ability to create a new ASP.NET Core Web Application (.Net CORE). This is our focus. Create a new project and select the Web Application Template.

selecttemplate

Un-select Host in the Cloud – We aim to host on Windows Server.

There are few things we need to create to get our site up and hosted by IIS8 within our Windows Server.

  • Microsoft DotNet Core Windows Server Hosting
  • Web Application on WebServer
  • Publishing Profile
  • Minor Tweaks to appSettings.Json

Out of the box appSettings.json should look something like the following

 

 {
    "ApplicationInsights":{
    "IntrumentationKey": {"0f723b60-5b54-4105-938d-c49eec544f7"
    },
    "Logging": {
    "IncludesScopes":false,
    "LogLevel": {
      "Default":"Debug",
      "System":"Information",
      "Microsoft:"Information"
     }
    }
   }

Install Hosting Bundle

server_hosting

 

Change Application Pool Settings:

application_pool

 

Navigate back to Visual Studio and Right-Click your web application project and select publish.

project_explorer

Here import the configured settings created from IIS when creating your website.

publish_1

After importing your settings and validating the  connection you should see the Settings page

publish_2

 

Hitting Preview is great if you really wish to see the changes that will occur without officially publishing.  (It’s along the lines of a “whatIf” if you are familiar with msbuild options)

If you have followed up to this point you should be presented with this awesome message -_-

error

Well that’s the little tad bit that was not told to us to host the app within IIS8 on Windows Server 2012. So what exactly do we have to do? Well first head bang into some dry wall. That always fixes it! Ok really there are some settings that have to be configured for our app to respond given how dotnet works. A great article is already written on this and really the guy (Rick Strahl) is way better versed at explaining this. Take a look at IIS and Asp,NET Core work here. https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications-with-IIS

Project.json

appsettings

gcServer vs System.GC.Server Issues with different variants – https://github.com/aspnet/Docs/issues/1237 Actual Documentation on appsettings.json – https://msdn.microsoft.com/enus/library/ms229357(v=vs.110).aspx

Very Simple Event log for the application:

Log Name: Application
Source: IIS AspNetCore Module
Date: 10/12/2016 4:58:42 AM
Event ID: 1000
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: NikolaT
Description:
Failed to start process with commandline '"dotnet" .\WebApplication1.dll', ErrorCode = '0x80070002'.
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
 <System>
 <Provider Name="IIS AspNetCore Module" />
 <EventID Qualifiers="0">1000</EventID>
 <Level>2</Level>
 <Task>0</Task>
 <Keywords>0x80000000000000</Keywords>
 <TimeCreated SystemTime="2016-10-12T04:58:42.000000000Z" />
 <EventRecordID>37256</EventRecordID>
 <Channel>Application</Channel>
 <Computer>NikolaT</Computer>
 <Security />
 </System>
 <EventData>
 <Data>Failed to start process with commandline '"dotnet" .\WebApplication1.dll', ErrorCode = '0x80070002'.</Data>
 </EventData>
</Event>

Simply means you need the Runtime also on the server along with the hosting bundle. Ugh headache achieved. I mean what is the point of adding the hosting bundle if I still cannot run my app. Lol really!!

sdk

Further Reading – References (Kertrel)

http://tostring.it/2016/01/12/Using-Kestrel-with-ASPNET-5/

http://benfoster.io/blog/how-to-configure-kestrel-urls-in-aspnet-core-rc2

http://andrewlock.net/configuring-urls-with-kestrel-iis-and-iis-express-with-asp-net-core/

0 comments on “Hosting DotNet Core Web Application on Windows Server (IIS8)Add yours →

Leave a Reply

Your email address will not be published. Required fields are marked *