While working with Dotnet core and Angular, I come across a requirement to deploy production code to server.I am going to share hosting method for Dotnet core Api and Angular 5 On IIS server.
Host Dotnet Core App On IIS
NOTE: I installed dotnet core version 2.1.200 in my machine.
I am assuming that you you have created Api project and ready to IIS configure.you can create api from here
When creating a new project you can see a Program.cs file in folder, and it contains the following code.
public class Program
{
public static void Main(string[] args)
{
var webHost = new WebHostBuilder()
.UseStartup<Startup>()
.Build();
webHost.Run();
}
}
Configure WebHostBuilder
In dotnet core application we have to define WebHostBuilder object for web server.Inside the WebHost object we have add some configuration for application hosting.
Add bellow methods in WebHostBuilder setup code
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
What does these method ?
UseKestrel() : kestrel is a cross-platform web server for asp.net core. and it's by default included in asp.net core project templates.
UseContentRoot : When you call dotnet run from your project folder without this function, the content root path is in your bin output folder.
UseIISIntegration() : If you are going to host your app ISS, the UseIISIntegration() method should be called as part of building the host.
And it will be work as revers proxy in front of Kestrel.
NOTE: Usekestrel and UseIISIntegration() are very different actions.IIS is only used as a reverse proxy.Usekestrel creates the server and hosts the code.UseIISIntegration specifies IIS as the reverse proxy server. And also examines environment variables used by IIS/IISExpress and makes decisions like which dynamic port use,which headers to set,etc.
What is AspNetCoreModule ?
As you can see the web.config file is available in your project root folder.
It’s only used when deploying your application to IIS. It registers the AspNetCoreModule as an HTTP handler. It handles all incoming traffic to IIS. And ensures that your application is running.
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
Okay… let’s move for server configuration
1) Install Dotnet Core Windows server hosting bundle
The deployment is not same as asp.net, there are some tooling for host your application. Before you deploy your application, you need to install the dotnet core hosting bundle for IIS. This will install .NET core runtime, libraries, and AspNetCoreModule.
Make sure you pick “windows server hosting”
2) Build and Publish
If you simply run this command…
dotnet publish
Your project will be published to the default location which is inside your application’s bin folder.
<YourApplication>\bin\Debug\netcoreapp2.0\publish
Here you will find a portable version of your project which can be hosted in any number of place including on Linux or via IIS on windows.
3) Create Application is IIS
Copy files to preferred IIS location where you want the files to live. If you are deploying to a remote server, you may want to zip up the files and move to the server.
Open IIS manager, create a new IIS Application Pool.you will want to create under the .NET CLR version of “No managed Code” Since IIS only works reverse proxy, it’s not actually executing any .NET code
Now Create your new application under your existing hosted sites,or create new ISS application.select your new IIS Application pool here.Point your published code.
4) Check and Run
Before run the application you need to check the AspNetCoreModule is present or not. To check go to Modules from application home and inside the Modules you can find that your application is running under AspNetCoreModule.
That’s it, Now you can run your app using Manage Application > Browse
good article on how to host DOT Net CORE API and Angular5 on IIS.
ReplyDeleteWaiting for the Part2
Thank you Sushil. will be publish second part soon.
ReplyDeleteVery nice blog thanks for this update
ReplyDeleteDot Net Online Course Hyderabad
Thanks Mounika..
DeleteHow to do the same thing for an Angular CLI application running against an ASP.NET Core application, i.e. an application that was created using "dotnet new angular". How to build and host both application components in IIS?
ReplyDeletethis +1
DeleteYour english is really hard to understand. For example: "I am assuming that you you have created Api project and ready to IIS configure.you can create..." should be "I am assuming that you have created an Api project and are ready to configure IIS. You can create...". It makes it really hard to decypher what you are trying to say.
ReplyDeleteGood job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
smm panel
ReplyDeletesmm panel
İs İlanlari
İnstagram takipçi satın al
Https://www.hirdavatciburada.com
beyazesyateknikservisi.com.tr
Servis
Jeton Hilesi
Congratulations on your article, it was very helpful and successful. ce8c4289b1bf7db55d1863935acc624b
ReplyDeletesms onay
numara onay
website kurma
Thank you for your explanation, very good content. 77f5a620307fb1bfea609e8387966fc4
ReplyDeletedefine dedektörü
Good content. You write beautiful things.
ReplyDeletevbet
vbet
sportsbet
taksi
korsan taksi
sportsbet
mrbahis
mrbahis
hacklink
Good text Write good content success. Thank you
ReplyDeletebonus veren siteler
tipobet
kralbet
kibris bahis siteleri
slot siteleri
mobil ödeme bahis
betpark
betmatik
Önemli giriş adreslerine buradan ulaşabilirsiniz.
ReplyDeletebetturkey giriş
betpark giriş
CW56S
erzurum
ReplyDeletekuşadası
ümraniye
beşiktaş
ataşehir
MZBYG
kağıthane
ReplyDeletemuğla
tuzla
etiler
maltepe
JNZLVG