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".
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.
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'.
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;
EXEC sp_addrolemember N'db_datareader' ,N'IIS APPPOOL\dotnetcoreapp'
EXEC sp_addrolemember N'db_datawriter' ,N'IIS APPPOOL\dotnetcoreapp
Check these permissions from your SGBD:
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.
Points of Interest
Thank you for reading this post. I hope that you appreciated it, and I'm waiting for your feedback .
- Initial version: 01/11/2016