The WebListener server (introduced in 1.1) has been expanded and rebranded in 2.0. Discover the new version HTTP.sys and learn how to use it instead of Kestrel and IIS.
- [Instructor] A change from 1.1 is WebListener is now named HTTP.sys, but it's not just a rebranding, it's actually a combination of the WebListener and Microsoft.Net.Http.Server packages. This is a package you would have to add in, and that is the Microsoft.AspNetCore.Server.HttpSys package, because it's not a standard server that is used with Asp.NetCore.
Recall from the 1.1 chapter that the WebListener, or now HTTP.sys, only works on Windows, and is useful for those cases where you need more of the Windows functionality exposed to your application than can be done through Kestrel. Like the WebListener, you can configure the authentication, and that is Schemes and AllowAnonymous, but you can also now configure max client connections, max request body size, and add in URL prefixes.
As a reminder, this will not work with IIS. It has to be one or the other. So let's look at how we use this in code. In the exercise files, lines 51 through 63 are commented out. To set this lab up, you will want to comment out the rest of main, and uncomment 51 through 63. Now it is important that, if you're going to run this sample, you set the SpyStore project itself as the startup, set as startup, and not run through Docker, because I am running on a Linux container, and I'm going to use a Windows-only server to run this.
So I have a helper method called UseNoServerBuilderOptions. This just takes all of the features of the create default builder, except for the UseKestrel and UseIISIntegration, and plugs them in. I then simply add UseHttpSys, adding in my options, use my startup, and then build. In my launch settings, just like I did in the 1.1 course, I added a new profile called WebListenerDemo, and this just changes the port that I'm going to run on.
Most of the options are exactly the same, and I probably should have renamed it HttpSysDemo, but this kept it consistent with the prior course. Because I am not running in Docker, I have the option to run that profile. I make sure it's selected, and I hit Run, and we'll see the app come up on port 55058. In the sample code, I'm not taking any advantages of Windows features, but you certainly could if you needed to.
And there we have our app running using HTTP.sys instead of Kestrel.
- Running and debugging ASP.NET Core applications
- Pros and cons of migrating existing applications to ASP.NET Core.
- Built-in dependency injection
- Environment awareness and app configuration
- Web host configuration and SSL
- View components invoked as tag helpers
- Configuration and logging
- Using Razor Pages