Gurpreet Kailey
Gurpreet Kailey

Reputation: 669

How to get IIS version in asp.net core

I am using asp.net core 2.0.

In c# code on server side I want to check the IIS version where the website is hosted.

Earlier in asp.net the following line gives us the iis version.

HttpContext.Current.Request.ServerVariables["SERVER_SOFTWARE"];

It was giving me the result like Microsoft-IIS/10.0

How to get the desired result in asp.net core ?

Upvotes: 3

Views: 2070

Answers (1)

itminus
itminus

Reputation: 25380

Updated my code to asp.net core 2.2, still not able to get the value of this variable

If you're using asp.net core 2.2 or above, get the IServerVariablesFeature as below:

var serverVars = HttpContext.Features.Get<IServerVariablesFeature>();
var iisVersion = serverVars == null ? null : serverVars["SERVER_SOFTWARE"]; 

Demo:

enter image description here

Upvotes: 5

Related Questions