如何在ASP.NET Core中获取IIS版本 [英] How to get IIS version in asp.net core

查看:148
本文介绍了如何在ASP.NET Core中获取IIS版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net core 2.0.

I am using asp.net core 2.0.

在服务器端的C#代码中,我想检查托管网站的IIS版本.

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

在asp.net的更早版本中,以下几行提供了iis版本.

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

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

这给了我类似 Microsoft-IIS/10.0

如何在asp.net核心中获得所需的结果?

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

推荐答案

将我的代码更新为asp.net core 2.2,仍然无法获取此变量的值

如果您使用的是asp.net core 2.2或更高版本,请按以下方式获取 IServerVariablesFeature :

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"]; 

演示:

这篇关于如何在ASP.NET Core中获取IIS版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆