Deploying ASP.NET 5 website on IIS without using Visual Studio

 

 

 

Recently I blogged about ‘Deploying the ASP.Net5 based MVC6 application on IIS which was developed using VS 2015’ .

 

The scope of this blog is to ‘Deploying ASP.NET 5 website on IIS with VS and configure the IIS to access this website’.

 

 

Below is the systematic approach to achieve this requirement:

 

I will be explaining the step by step procedure using the MVC6 sample application downloaded from below location which is available in the githubsite:

 

https://github.com/aspnet/Home/

 

Step 1:

You then need to create a folder structure like below:

 

clip_image002[4]

 

 

Step 2:

Under approot folder you need to place the CoreCLR runtime version needed for your application.

You can get this from the User Profiles location:

 

 

clip_image004[4]

 

 

 

Note: If you wonder- “How I got the various CoreCLR runtime versions within my user profiler ?”
Refer this blog.

 

You need to copy the concerned runtime version and place it under the runtimes folder within the approot.

In my scenario, I have used dnx-coreclr-win-x64.1.0.0-rc1-update1 runtime and placed it under the runtimes folder within the approot as shown below:

 

 

clip_image006[4]

 

 

Step 3:

 

Create a folder src and place your application folder which has the source code contents within this, as shown below:

 

 

clip_image008[4]

 

clip_image010[4]

 

 

 

Note: Remove the wwwroot from your application and paste its contents within the wwwroot folder that you have created in Step 1 .

 

 

Step 4:

 

Create a cmd file restorePackages.cmd within the approot folder. Place the below content within this cmd file:

 

 

 

SET DNX_FOLDER=dnx-coreclr-win-x64.1.0.0-rc1-update1

SET "LOCAL_DNX=% ~dp0runtimes\%DNX_FOLDER%\bin\dnu.cmd"

 

@"%LOCAL_DNX%" restore --packages "% ~dp0packages" "% ~dp0src\HelloMVC"

 

 

 

This cmd file would be used to restore the packages. This cmd file internally runs the dnu restore command on your application and creates the folder ‘packages’ within the approot folder.
 

 

In the script, ‘ ~dp0 ’ stands for absolute path of approot folder.

 

 

Make sure that you modify the above highlighted section accordingly as per your application requirements.

 

 

Step 5:

 

Create a file called global.json within the approot folder and place the below content within it:
 

 

 

 

{

  "projects": [

    "src"

  ],

  "sdk": {

    "version": "1.0.0-rc1-update1"

  },

  "packages": "packages"

}

 

 

 

global.json file would be used by the application inside the src to use the concerned runtime version load the dependencies from the packages folder. Note the above highlighted section which needs to be modified accordingly.

 

 

 

Step 6:

 

You need to then navigate to the approot folder from elevated CMD prompt and run the restorePackages.cmd file.

 

 

 

C:\inetpub\DNX_Demo\final_DNX_Demo\approot>restorePackages.cmd

 

C:\inetpub\DNX_Demo\approot>SET DNX_FOLDER=dnx-coreclr-win-x64.1.0.0-rc1-update1

 

C:\inetpub\DNX_Demo\approot>SET "LOCAL_DNX=C:\inetpub\DNX_Demo\approot\runtimes\dnx-coreclr-win-x64.1.0.0-rc1-update1\bin\dnu.cmd"

Microsoft .NET Development Utility CoreClr-x64-1.0.0-rc1-16231

 

  CACHE https://api.nuget.org/v3/index.json

Restoring packages for C:\inetpub\DNX_Demo\approot\src\HelloMVC\project.json

Writing lock file C:\inetpub\DNX_Demo\approot\src\HelloMVC\project.lock.json

Restore complete , 1562ms elapsed

 

 

 

 

Step 7:

 

Create a file called web.cmd with the below contents within the approot folder:

 

 

 

 

@echo off

SET DNX_FOLDER=dnx-coreclr-win-x64.1.0.0-rc1-update1

SET "LOCAL_DNX=%~dp0runtimes\%DNX_FOLDER%\bin\dnx.exe"

 

IF EXIST %LOCAL_DNX% (

  SET "DNX_PATH=%LOCAL_DNX%"

)

 

for %%a in (%DNX_HOME%) do (

    IF EXIST %%a\runtimes\%DNX_FOLDER%\bin\dnx.exe (

        SET "HOME_DNX=%%a\runtimes\%DNX_FOLDER%\bin\dnx.exe"

        goto :continue

    )

)

 

:continue

 

IF "%HOME_DNX%" NEQ "" (

  SET "DNX_PATH=%HOME_DNX%"

)

 

IF "%DNX_PATH%" == "" (

  SET "DNX_PATH=dnx.exe"

)

 

@"%DNX_PATH%" --project " %~dp0src\HelloMVC" --configuration Release web %*

 

 

Now looking into the final folder structure, you will see the below:

 

 

clip_image012[4]

 

 

Step 8:

 

Open the wwwroot folder and create a web.config file under this with the below contents:

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

    <system.webServer>

   <handlers>

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

           modules="httpPlatformHandler" resourceType="Unspecified" />

    </handlers>

    <httpPlatform processPath=" ..\approot\web.cmd" startupTimeLimit="3600"

        stdoutLogEnabled="true" stdoutLogFile=" ..\logs\stdout.log" />

    </system.webServer>

</configuration>

 

 

 

We are all set now, to create our website in IIS.

 

 

Configuring the IIS to proxy the request to DNX:

 

 

 

  • Open the IIS Manager and create a test site and point it to the wwwroot folder that you created in Step 1 above

 

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

 

clip_image014[4]

 

 

· You can browse it now to see if your application comes up fine.

 

 

clip_image016[4]

 

If you run in to any issues, you can refer to the logs under the ..\logs\stdout.log file.

 

Alternatively, you can also enable the Failed Request Tracing Rules available in IIS to see if you can identify the cause and take suitable actions to fix it.