Partilhar via


Deploying ASP.NET5 based MVC6 application in IIS

 

 

 

I couldn’t find any blogs in the internet which explains the step by step procedure to deploy the ASP.NET 5 application to IIS from Visual Studio 2015.

 

This blog is written specifically to address this issue.

 

Scenario :

 

I will be creating an MVC 6 application in my Visual Studio 2015 Update 1 and deploy to my local IIS and explain how to configure the HTTP Platform Handler.

 

Steps to be followed :

 

Deploy from VS 2015

 

Ø Firstly, we create the sample MVC 6 application. For this you need to Open VS 2015. Click on FileàNew Projectà Under the New ASP.Net Project template window you can select any one of the below options. I have selected the WebApplication in my example.

 

clip_image002

 

 

 Ø Right click on the WebApplication under the Solution Explorer and select Publish

  

clip_image004

 

 Ø In the Publish Web window, under the Profile tab, you can select File System.  You will be asked to Enter a Profile Name as shown below:

 

clip_image006

 

 

Ø Under the Connection tab, you need to specify the Target location:

 

 

clip_image008

 

 

Ø Under the settings tab, you need to select the Target DNX Version, this is the runtime versionagainstwhich our application will be compiled.

 

 

clip_image010

 

 

 Ø Under the Preview Tab you can simply click on the Publish button which will deploy your application content to the Target Location specified in step 4

 

While this happens the Visual Studio will send the information we provided as a parameter to the dnu.cmd location under your user profile Target DNX version selected above.

 

 

Connecting to c:\Inetpub\ASPNet_Demo...

Environment variables:

Path=.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External;%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\git

C:\Users\xxxxx\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin\dnu.cmdpublish "c:\users\xxxxx\documents\visual studio 2015\Projects\AspNet_Demo\src\AspNet_Demo" --out "C:\Users\xxxxx\AppData\Local\Temp\PublishTemp\AspNet_Demo98" --configuration Release --runtime dnx-clr-win-x86.1.0.0-rc1-update1 --wwwroot "wwwroot" --wwwroot-out "wwwroot" --iis-command "web" --quiet

Microsoft .NET Development Utility Clr-x86-1.0.0-rc1-16231

Executing script 'prepublish' in project.json

 

 

Then internally the code is published with the help of msdeploy.

 

 

Publishing with publish method [FileSystem]

Publishing files to c:\Inetpub\ASPNet_Demo

Executing command ["C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:contentPath='C:\Users\xxxxx\AppData\Local\Temp\PublishTemp\AspNet_Demo98\' -dest:contentPath='c:\Inetpub\ASPNet_Demo' -verb:sync -enableRule:DoNotDeleteRule -retryAttempts:2 -disablerule:BackupRule]

Info: Adding directory (c:\Inetpub\ASPNet_Demo\approot).

 

 

Configuring in IIS:

 

 Ø Directory structure after publishing:

 

 

clip_image012

 

 

Ø In the IIS you need to create new website and point it to the wwwroot folder shown above. So the site in IIS would be pointing to the path C:\inetpub\ASPNet_Demo\wwwroot.

 

Ø Set the application pool to No Managed Code. ASP.NET 5 runs in a separate process and manages the runtime.

 

 

clip_image014

 

 

 Ø You also need to install the HttpPlatformHandler from WebPI tool.

 

The HttpPlatformHandler is an IIS Module which does the following two things:

· Process Management of http listeners – this could be any process that can listen on a port for http requests. For example – Tomcat, Apache, Jetty, Node.exe, Ruby etc;

· Act like a Proxy for the incoming requests to the process that it manages.

 

Ø We can configure the settings for HttpPlatformHandler at the website level from Configuration Editor:

 

 

clip_image016

 

 

Ø Below are the default settings that you get after you publish the application:

 

 

clip_image018

          

  Ø These settings are picked up from the web.config file under the wwwroot. The web.config file which should have the below lines:

 

 

 

 

<configuration>

  <system.webServer>

    <handlers>

      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler"

      resourceType="Unspecified" />

    </handlers>

    <httpPlatform processPath=" ..\approot\web.cmd" arguments=""

       stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout.log"

       startupTimeLimit="3600">

    </httpPlatform>

  </system.webServer>

</configuration>

 

Ø We see that the ProcessPath is set to ..\approot\web.cmd. This specifies the ‘Path to the executable or script that will launch a process listening for HTTP requests’.

 

Ø We see that the web.cmd file exits under the approot which is in the same location as that of wwwroot folder.

 

 

clip_image020

         

Ø You can also see the runtimes folder which has the DNX target version against which our application is compiled. This is the same target version we selected while publishing the application.

 

 

clip_image022

 

 

Ø Now the ASP.NET5 based MVC 6 application has been deployed successfully on IIS. We can browse it and check the page comes up fine:

 

 

clip_image024

 Troubleshooting:

If you run into any issues, after configuring the website you need to follow this blog.