Reputation: 1191
I use c# .net core on linux. I want to see what server options and what server name I use. I know server name must be Kestrel and options must be something like this:
But how to get this info in runtime?
Upvotes: 2
Views: 3617
Reputation: 12082
You can get the Server information by injecting the IServer service. Which will be the actual server instance running. From there you can access the KestrelServerOptions
in the Options property.
Here is a sample code snippet where I inject it in a controller and get the options.
public WeatherForecastController(ILogger<WeatherForecastController> logger, IServer webServer)
{
_logger = logger;
KestrelServer kestrelServer = webServer as KestrelServer;
if (kestrelServer == null)
{
throw new Exception($"Not running inside Kestrel server. The current server type is {webServer.GetType().FullName}");
}
else
{
KestrelServerOptions kestrelServerOptions = kestrelServer.Options;
// do something with the options
}
}
Upvotes: 3