Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / IIS

How to Publish ASP.NETCore MVC Web Application to IIS in Less Than 5 Minutes

5.00/5 (6 votes)
1 Nov 2016CPOL1 min read 19.3K  
A good tutorial in how you can publish your ASP.NETCore MVC web application to IIS.

Introduction

This tip will give you an easy way to publish your ASP.NETCORE web application to IIS.

Using the Code

In this tip, I will try to publish my last demo (CRUD-in-ASP-NETCore-MVC-with-Angular-and-Web-Api) to IIS. To understand this tutorial well, I recommend you download the project.

A) Setup IIS

I recommend you follow steps from this link: how-to-install-iis-on-windows.

B) Second: Export your ASP.NETCORE Project

Open your cmd command-line, navigate to the project root folder and write the below command-line:

dotnet publish --framework netcoreapp1.0 --output [destination folder] --configuration Realease

[destination folder ]: the directory name that will contain the publish result. For example : "E:\website\dotnetcoreapp".

Image 1

C) Create a New Website from Your IIS Manager

Open the IIS manager and add a new web site: for example, dotnetcoreapp that has 'E:\website\dotnetcoreapp' as a physical path.

Image 2

D) Set the .NET CLR Version

In IIS MANAGER, find the Application Pool related to your website, and change the .NET CLR version to 'No Managed Code'.

Image 3

E) Grant Permissions to Your IIS App Pool

This step is very important, if you want to avoid exceptions related to the database connection failure.

Open your SGBD (in this example, I will show you TSQL instructions for SQL SERVER), write the following commands, to create a new account in SQL Server for your IIS Application Pool and grant Read and Write permissions to your specific database.

SQL
CREATE LOGIN [IIS APPPOOL\dotnetcoreapp] FROM WINDOWS;
go 
use DataBaseDotnetCore
 
EXEC sp_addrolemember N'db_datareader' ,N'IIS APPPOOL\dotnetcoreapp'
go
EXEC sp_addrolemember N'db_datawriter' ,N'IIS APPPOOL\dotnetcoreapp

Check these permissions from your SGBD:

Image 4

F) Open the Web Site

Finally, open the given url (http://localhost:8082/), you should be able to display the default page (index.html) and to retrieve data from your database.

Image 5

Points of Interest

Thank you for reading this post. I hope that you appreciated it, and I'm waiting for your feedback .

History

  • Initial version: 01/11/2016

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)