Click here to Skip to main content
15,884,986 members
Articles / Web Development / IIS
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
1 Nov 2016CPOL1 min read 18.8K   7   2
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)


Written By
Technical Lead
France France
Microsoft certified professional in C# ,HTML 5 & CSS3 and JavaScript, Asp.net, and Microsoft Azure.

Comments and Discussions

 
QuestionWill this work with older IIS version such as version 7.x windows 2008 server r2? Pin
Member 127940773-Nov-16 1:43
Member 127940773-Nov-16 1:43 
AnswerRe: Will this work with older IIS version such as version 7.x windows 2008 server r2? Pin
O.Nasri3-Nov-16 4:48
professionalO.Nasri3-Nov-16 4:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.