Posted on March 16, 2019 inASP.NET-Kern,developer,IIS- 4 comments
This is Part II of a series of blog posts where I share some ways to build and deploy a core ASP.NET application for IIS running in a Windows VM. In whichprevious post, covers creating and publishing a core ASP.NET application. The end result is an artifact (a published directory). In this post, I'll cover how to implement the artifact in IIS. Along the way, we'll discuss:
- IIS is on
- .NET Core Runtime e Hosting-Bundle
- Configuring IIS Applications and Websites
- IIS Application Pool
overview
Here are the steps for deploying a typical basic ASP.NET application to IIS for the first time.
- IIS is enabled.
- Install the .NET Core hosting and runtime package.
- Create and configure the IIS root application and website
- Create and configure the application pool.
- Create an IIS website.
- add links
- SSL certificate
- Set the physical path to the directory containing the application files.
- If you're deploying the app as a separate app from the root app, create and configure the app on the site.
- Set the physical path to the directory containing the application files.
IIS is on
Follow these steps to verify and enable IIS as needed:
- open server manager
- You can search for it in the Start menu.
- In Server Manager, on the Quick Launch, click Add Roles and Features. The Add Features and Feature Wizard window will appear.
- Click Next.
- Under Select installation type, check "Role-based or role-based installation".
- Under Select Destination Server, select the server on which you want to enable IIS and click Next.
- Under Server Roles, enable "Web Server (IIS)".
- The system automatically selects default modules for IIS. In addition to the standard components, you can also install the Application Initialization module in Application Development if you want the application to start automatically instead of waiting for the first request. See my post for more details:How to automatically start an ASP.NET Core web app and keep it running in IIS.
- Click Next.
- Click Install.
.NET Core Runtime e Hosting-Bundle
If you choose to use Framework Dependent Deployment (FDD) when publishing your app, the server running your app must have the appropriate .NET Core runtime installed. Run the following command to check the available runtime on a server:
dotnet--info
To use: To use the dotnet command tools, you must install theSDK.
Below is an example of .NET Core runtimes installed in a Windows virtual machine.
Installed .NET Core runtimes:
Microsoft.AspNetCore.All 2.1.3 [C:\Programa\dotnet\shared\Microsoft.AspNetCore
Microsoft.AspNetCore.All 2.2.2 [C:\Programa\dotnet\shared\Microsoft.AspNetCore
Microsoft.AspNetCore.App 2.1.3 [C:\Programa\dotnet\shared\Microsoft.AspNetCore
Microsoft.AspNetCore.App 2.2.2 [C:\Programa\dotnet\shared\Microsoft.AspNetCore
Microsoft.NETCore.App 2.1.3 [C:\Programa\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.2 [C:\Programa\dotnet\shared\Microsoft.NETCore.App]
The above runtimes mean that the server can support any FDD of an app targeting .NET Core between 2.0.0 and 2.2.2, thanks to the rollforward feature available from .NET Core 2.0.0.
Download and install the latest hosting and runtime package. As of this writing, the latest .NET core stable runtime is 2.2. you can find ithere.
Caution: You must enable IIS first before installing the runtime and hosting package. If you install the package without activating IIS, you must run setup again and select repair after activating IIS.
Restart the server after installation.
application groups
Basically, an application pool allows you to control the resources of a web application. For example, you can have multiple applications share the same resources by assigning them to the same group, or you can assign dedicated resources to an application by assigning the application to an application group separate from other groups.
An application group also acts as a sandbox to effectively isolate applications within the group from applications in another group. If an application running in one application pool crashes or causes problems, applications running in another application pool will not be affected. You can have multiple apps sharing the same group, and you can also have multiple groups for different apps. Each application group represents a worker process. So the more application pools you have, the more memory you need.
When you stop a group of apps, you essentially stop the apps associated with the group.
local do IIS
A website is a container for web applications. Each site has a default root application, and you can create additional applications on the site. All apps on the same site share the same root URL (link).
Although apps on the same site use the same links, each app can have its own app group. Therefore, you can still achieve application isolation when hosting multiple applications on the same website. Of course, you can also host multiple apps in multiple locations.
You can host multiple applications on the same site to reuse DNS or if the applications are closely related. Suppose you have two related applications; maybe two different API versions of the same application. You can host both apps on the same website. Both have the same root URL but different end paths (eg myapi.com/v1 and myapi.com/v2).
Union
A site binding essentially tells IIS that a site can process a request if the request header matches one or more parts of the binding. The main parts of a link are the type, IP address, port and hostname. When an incoming request arrives at the server, IIS can determine which site is best suited to handle the request based on the sites' bindings.
A bond mainly consists of:
Type: http or https. With https, you can associate an SSL certificate with the link.
hostname: One or more hostnames can be assigned to a server. Default is blank or localhost. The hostname in the request address must match the hostname in the link for the site to process the request.
porto: The TCP port number. This is a required configuration. Specify the port number to which you want to link the site. The port number specified in the request address must match the port number in the site binding to process the request.
IP address: More than 1 IP address can be assigned to a server. When configuring a link to a website, you can select a specific IP assigned to a server. You can also select the All Unassigned value, which means all IP addresses that have not been assigned to other IIS sites. If the request address is in the form of an IP address, the request IP address must match the mandatory IP address of the website to process the request.
SSL certificate
An SSL certificate is used to prevent secure communication between a server and a clientthe man in the middleAttack.
Here's a summary of how SSL works. For more details see theArticle.
How to get an SSL certificate:
- Create a certificate signing request.
- Submit the certificate signing request to a certificate authority (CA). The request contains the public key.
- The CA creates the certificate based on the public key. You don't know the private key.
- Install the certificate on your server.
Communication between browser and server via SSL:
- The browser creates a session key and encrypts it with the server's public key.
- The browser sends the encrypted key to the server.
- The server decrypts the session key with its private key.
- The browser and server now encrypt and decrypt the data with the session key, which is known only to the browser and the server.
You can also use a self-signed certificate for testing purposes. look thismail.
Deploy a sample ASP.NET Core app
For demonstration purposes, I've created and published a simple basic ASP.NET application. The app targets .NET Core 2.2.
On the remote server I have the published folder at "C:\inetpub\MyAspNetCoreApp".
I. Create IIS Application Pool
To create an application group,
- In IIS, click on the server name.
- Select "Application Pools" and right-click.
- Click Add Application Pool. to open the Add Application Pool dialog.
- For Name, enter "MyAspNetCoreAppPool".
- Under .NET CLR Version, select No Managed Code.
- For Managed Pipeline Mode, leave the default setting of Integrated.
- Check the Start application pool immediately box.
.NET CLR version:
The .NET CLR version refers to the version of the common language runtime that includes the .NET Framework. Since, in this example, we are deploying a core ASP.NET application targeting the .NET core and not the .NET core, we chose No Managed Code.
Shows the .NET Framework version used by an application pool. If the application pool has been configured to not use the .NET Framework, the value isNo managed code.
application groups(Video) Configuring a Web Server for Web Deploy Publishing (Web Deploy Handler)Windows server 2016/2019
Managed plumbing mode: integrated versus classic
this stack overflowmailtalks about the differences between integrated and classic modes. The main points comedocumentation🇧🇷 Below is just my summary.
Integrated mode is the latest mode available since IIS 7.0. Integrated mode unifies the processing models of IIS and ASP.NET. In integrated mode, an ordered list of events processes a request and generates a response.
Classic mode separates the rendering models of IIS and ASP.NET. In classic mode, a request goes through native processing in IIS. It then passes through Aspnet_isapi.dll for managed code processing.
Some of the processing steps, e.g. Handlers such as authentication and authorization are the same in the IIS and ASP.NET processing models. Therefore, it is less efficient than integrated mode because one request must be processed twice. If you are deploying a new application, be sure to choose integrated mode.
II Create an IIS site.
- In IIS, under Sites, right-click and select Add Site to open the Add Site dialog box.
- For Site Name, enter MyAspNetCoreApp.
- Click Select to open the Select Application Pool dialog and select the MyAspNetCoreApp pool you created earlier.
- Under Physical path, click Browse and select the path to the published app. For this example, I've placed the published app at C:\inetpub\MyAspNetCoreApp.
- Enter the information for the link. See the previous section for more details. For this example, just use the default values.
- Select "http" as the type.
- Select "All Unassigned" as the IP address.
- Select 8080 as port
- Leave the Hostname field blank to use the default localhost.
- Click OK to create the site.
- Run the app.
- Under Sites, select your MyAspNetCoreApp site. In the right pane, under Manage Site, click Start if the site is not already started.
- On the server, open your browser and type "http://localhost:8080".
You should see the page load. If so, congratulations.
Next steps:Once your site has been loaded locally, you can configure the link to allow the world to access your site.
- Add a new link using the DNS associated with your server.
- USA https.
In the next post, I'll show you how to automate the build and deployment process using Azure Pipelines.
4. Troubleshooting
If you get HTTP 500.19: Internal Server Error. The server might not have the correct .Net Core runtime installed. See this disc.
One way to fix the problem is to run the application directly with the dotnet command.
Open the command line, CD in the directory with the application files: C:\inetpub\MyAspNetCoreApp. Then type the command
dotnet AspNetCoreApp.dll
You should be able to browse the app on port 5000.
V. What next?
read my nextmailIn this series, you'll learn how to automate the build and deployment process to save time, reduce human error, and focus more on building your app.
references
Create and publish a core ASP.NET application with Visual Studio 2017.
Quick Reference: IIS Application Pool
Understand IIS bindings, websites, virtual directories, and ultimately application pools
Differences between Integrated and Classic mode in App Pool
How to configure website links in Internet Information Services (IIS).
hang tags:application pool,dotnet core runtime and hosting package,is required,their website