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](/KB/applications/1151780/Image1-r-700.PNG)
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](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
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](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
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.
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](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
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](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
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
Microsoft certified professional in C# ,HTML 5 & CSS3 and JavaScript, Asp.net, and Microsoft Azure.