banner



How To Host A Web Api Service In Iis

Previously, nosotros discussed the differences betwixt Kestrel vs IIS. In this article, we volition review how to deploy an ASP.NET Cadre application to IIS.

Deploying an ASP.NET Core app to IIS isn't complicated. However, ASP.Internet Core hosting is dissimilar compared to hosting with ASP.Internet, because ASP.Internet Core uses different configurations. You may read more than well-nigh ASP.NET Core in this entry.

On the other hand, IIS is a web server that runs on the ASP.NET platform inside the Windows OS. The purpose of IIS, in this context, is to host applications built on ASP.NET Cadre. There'southward more information on IIS and ASP.NET in our previous blog, "What is IIS?"

In this entry, we'll explore how to brand both ASP.NET Cadre and IIS work together. Without further ado, let's explore the steps on how nosotros tin deploy ASP.NET Core to IIS.


New call-to-action


How to Configure Your ASP.Net Core App For IIS

The starting time thing you lot will notice when creating a new ASP.NET Core project is that it's a console application. Your project now contains a Plan.cs file, just similar a console app, plus the following lawmaking:

public class Program {     public static void Main(string[] args)     {         var host = new WebHostBuilder()             .UseKestrel()             .UseContentRoot(Directory.GetCurrentDirectory())             .UseIISIntegration()             .UseStartup()             .Build();          host.Run();     } }        

What is the WebHostBuilder?

All ASP.NET Cadre applications require a WebHost object that essentially serves equally the application and spider web server. In this case, a WebHostBuilder is used to configure and create the WebHost. You will normally see UseKestrel() and UseIISIntegration() in the WebHostBuilder setup code.

What practise these practice?

  • UseKestrel() – Registers the IServer interface for Kestrel as the server that will exist used to host your application. In the future, there could be other options, including WebListener which will be Windows but.
  • UseIISIntegration() – Tells ASP.NET that IIS will exist working as a contrary proxy in front of Kestrel and specifies some settings around which port Kestrel should mind on, forward headers and other details.

If you are planning to deploy your application to IIS, UseIISIntegration() is required

What is AspNetCoreModule?

You may have noticed that ASP.NET Core projects create a web.config file. This is only used when deploying your application to IIS and registers the AspNetCoreModule as an HTTP handler.

Default web.config for ASP.Cyberspace Core:

<?xml version="i.0" encoding="utf-8"?> <configuration>   <organisation.webServer>     <handlers>       <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>     </handlers>     <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="fake"/>   </system.webServer> </configuration>        

AspNetCoreModule handles all incoming traffic to IIS, then acts as the opposite proxy that knows how to manus traffic off to your ASP.NET Core application. You lot tin can view the source code of it on GitHub. AspNetCoreModule also ensures that your web awarding is running and is responsible for starting your process upward.

Install .Cyberspace Core Windows Server Hosting Bundle

Before y'all deploy your application, you need to install the .NET Cadre hosting bundle for IIS – .NET Core runtime, libraries and the ASP.NET Core module for IIS.

After installation, you lot may need to practise a "net stop was /y" and "net start w3svc" to ensure all the changes are picked up for IIS.

Download: .NET Cadre Windows Server Hosting<- Make sure you selection "Windows Server Hosting"

Steps to Deploy ASP.Internet Core to IIS

Before you deploy, you need to make certain that WebHostBuilder is configured properly for Kestrel and IIS. Your web.config file should also be and look similar to our example above.

Step 1: Publish to a File Binder

Step 2: Copy Files to Preferred IIS Location

At present y'all need to copy your publish output to where you lot want the files to alive. If you are deploying to a remote server, you may want to zip up the files and motility to the server. If you are deploying to a local dev box, you can copy them locally.

For our case, I am copying the files to C:\inetpub\wwwroot\AspNetCore46

You will notice that with ASP.NET Core, there is no bin binder and information technology potentially copies over a ton of different .NET DLLs. Your awarding may also exist an EXE file if you are targeting the full .Net Framework. This picayune sample projection had over 100 DLLs in the output.

Pace 3: Create Application in IIS

While creating your awarding in IIS is listed as a single "Footstep," you will take multiple actions. Beginning, create a new IIS Application Pool under the .NET CLR version of "No Managed Lawmaking". Since IIS just works as a reverse proxy, it isn't really executing any .NET code.

Second, yous can create your awarding under an existing or a new IIS Site. Either way, you will want to pick your new IIS Application Pool and signal it to the binder y'all copied your ASP.NET publish output files to.

Stride 4: Load Your App!

At this point, your application should load only fine. If it does not, check the output logging from it. Within your web.config file you define how IIS starts upwardly your ASP.Internet Cadre process. Enable output logging by setting stdoutLogEnabled=true. You may too want to change the log output location equally configured in stdoutLogFile. Check out the instance spider web.config before to see where they are ready.

Advantages of Using IIS with ASP.NET Core Hosting

Microsoft recommends using IIS with any public facing site for ASP.NET Core hosting. IIS provides additional levels of configurability, management, security and logging, among many other things.

Check out our blog post about Kestrel vs IIS to run into a whole matrix of feature differences. The post goes into more depth virtually what Kestrel is and why you need both Kestrel and IIS.

I of the big advantages to using IIS is the process management. IIS will automatically offset your app and potentially restart it if a crash were to occur. If you lot were running your ASP.NET Core app as a Windows Service or panel app, you would not have that safety net there to start and monitor the process for you.

Speaking of safety nets, your awarding performance should exist the top priority. Which is why you demand an application performance monitoring tool that allows you to deploy robust applications.

Endeavor Retrace for APM! Retrace is an application performance monitoring tool compatible with multiple development platforms. You can easily runway deployments and improvements through the insight-based dashboards. The tool provides you key metrics so you can easily see which areas need attention.

Get your Free 14-Day Trial today!

  • Almost the Author
  • Latest Posts

How To Host A Web Api Service In Iis,

Source: https://stackify.com/how-to-deploy-asp-net-core-to-iis/

Posted by: cainshead1975.blogspot.com

0 Response to "How To Host A Web Api Service In Iis"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel