Home > other >  How can I know if my app is running under Kestrel or HTTP.sys?
How can I know if my app is running under Kestrel or HTTP.sys?

Time:03-15

What's the best way to know if my app is running under Kestrel or HTTP.sys. All that I have found so far is to check for "Kestrel" in one of the HttpConext property class names.

Within an MVC controller I can do something like this:

Boolean IsKestrel = HttpContext.Features.GetType().ToString().Contains("Kestrel");

i.e. check this:

Features = {Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection<Microsoft.AspNetCore.Hosting.HostingApplication.Context>}

When using HTTP.sys I only get:

Features = {Microsoft.AspNetCore.Http.Features.FeatureCollection}

(Is "Http" here enough to know that this is HTTP.sys?)

There must be a better way. Is there an obvious property somewhere that contains the name of the host being used?

A broader question might be, how do I know what the builder pattern built?

CodePudding user response:

you can use System.Diagnostics.Process.GetCurrentProcess().ProcessName

CodePudding user response:

I am not sure whether you want to check this information using the code only or you are just looking for a way to know on which web server your app is running.

In my search result, I found that we could set the ports for a specific web server. When the application will run on that specific web server then it will use that pre-configured port. I am assuming your app also has a similar configuration. You could set the different ports for Kestrel, Http.sys, or IIS. By checking the port number you could say that on which web server your site is running.

You could try to go to the launchSettings.json file in your project where you could configure ports for IIS and Kestral.

enter image description here

Helpful References:

  1. Kestrel Web Server in ASP.NET Core

  2. Understand HTTP.sys Web Server In ASP.NET Core

  • Related