How to use the IIS core to ASP.NET & ASP.NET core Hosting how it works

in utopian-io •  7 years ago  (edited)

Hi everyone, on this occasion I will share a tutorial, may be useful for all of us,
In this article, we will review how to deploy applications to the IIS core ASP.NET. Deploying applications ASP.NET core for IIS is not complicated, but the core of the ASP.NET hosting is a little different from the ASP.NET.

How to configure application ASP.NET your core for IIS
The first thing you'll notice when creating a new project ASP.NET Core are those who really console applications. Your project now contains the Program.cs file as a console application will have and contains the following code:


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

What Is WebHostBuilder?
All applications require a core object ASP.NET WebHost which basically serves as the application and the web server. WebHostBuilder is used to configure and create the WebHost. You will typically see UseKestrel () and UseIISIntegration () in WebHostBuilder the configuration code.

What it do?

UseKestrel ()-this register IServer interface for Kestrel as a server that will be used to host your application. In the future, there may be other options, including the WebListener is going to be Windows only.
UseIISIntegration ()-this tells ASP.NET that IIS will work as a reverse proxy in front of Kestrel. This then determines some settings around the port that Kestrel must listen to, forwarding headers, and other details.

What Is AspNetCoreModule?
You may have noticed that the ASP.NET core projects create Web.config files. This is only used when You deploy applications to IIS. Then register AspNetCoreModule as an HTTP handler.

The default Web.config for the core ASP.NET:


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.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="false"/>

AspNetCoreModule handles all incoming traffic to IIS and acting as a reverse proxy that knows how to hand traffic from ASP.NET your core applications. You can see that the source code on GitHub. It also ensures that your web application is running. It is responsible to initiate your process.

Install the core Windows .NET Server Hosting Bundle
Before you deploy your application, you need to install .NET hosting core bundle for IIS. This will install the .NET runtime core, ASP.NET core library and module for IIS.

After installation, you may need to do a "net stop is/y" and "net start w3svc" to make sure all the changes made to IIS.

Steps to deploy the core ASP.NET to IIS
Before using, you need to make sure that the WebHostBuilder is configured correctly to use the Kestrel and IIS. Web.config you should also exist and look similar to the example above.

Step 1: publish to Folder files

gb 1.jpg

Step 2: copy the file to the location of the IIS option
Now you need to copy the output to publish Your files to where you want to live. If you use the remote to the server, you may want to zip up the files and move to the server. If you are using a local dev box, you can copy them locally.

As my example, I copy the file to C:\inetpub\wwwroot\AspNetCore46

You will see that with ASP.NET core there is no bin folder and it's potentially a copy over tons of different .NET etc. Your application may also be EXE files if you are targeting a full .NET Framework. My little sample project has over 100 output etc.

gb 2.jpg

Step 3: create an application in IIS
First, create a new IIS application pool. You will want to make one under the .NET version of the CLR "didn't work". Because IIS only works as a reverse proxy, it's really not any .NET code executes.

Second, make a new application under the IIS your existing site, or create a new IIS site. However, you will want to choose the IIS application pool you have and the point at which folders You copied ASP.NET you publish output file.

gb 3.jpg

Step 4: Load your application!
At this point, the application should load only. If not, check the log output from it. In the Web.config file you specify how IIS starts ASP.NET your core processes. Enable logging output by setting stdoutLogEnabled = true and You may also want to change the location of the output log as configured in stdoutLogFile. Check out the example Web.config before to see where they are.

The advantage of using IIS with ASP.NET core Hosting
Microsoft recommends using IIS with public facing sites to ASP.NET core hosting. IIS provides an extra level of konfigurabilitas, management, security, logging, and many other things. Check out my blog post about Kestrel IIS vs. matrix to see the entire feature differences. He goes more in-depth about what Kestrel and why you need both Kestrel & IIS.



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Your contribution cannot be approved because it does not follow the Utopian Rules, and is considered as plagiarism. Plagiarism is not allowed on Utopian, and posts that engage in plagiarism will be flagged and hidden forever.

You can contact us on Discord.
[utopian-moderator]