【问题标题】:the type or namespace name 'HttpBrowserCapabilitiesBase' does not exist in the namespace 'System.web' in .net core 2.2.net core 2.2 的命名空间“System.web”中不存在类型或命名空间名称“HttpBrowserCapabilitiesBase”
【发布时间】:2020-07-22 10:22:58
【问题描述】:

.netcore2.2 中执行代码时出现标题错误。

以下是我的代码,

var browser = Request.Browser;
System.Web.HttpBrowserCapabilitiesBase myBrowserCaps = browser;

HttpBrowserCapabilitiesBase 在此关键字中显示标题错误。

虽然此代码在 以下 .netcore2.2 下完美运行。 HttpBrowserCapabilitiesBase是.netcore2.2下面System.web DLL的接口。

这意味着更新的 .net 框架,这个命名空间现在不存在,哪个命名空间可以工作,我没有得到。

【问题讨论】:

    标签: c# browser asp.net-core-2.2 system.web httpbrowsercapabilities


    【解决方案1】:

    根据您需要的信息,您可以在标题中查找它(例如 Request.Headers["User-Agent"],如 here 所示),或者使用像 Device Detection 这样的库来获取它。

    编辑:这是使用ASP.NET Core Detection 库获取设备类型信息的教程:

    • 安装Wangkanai.Detection NuGet 包。
    • 添加到Startup.cs 中的ConfigureServices 方法:

      services.AddDetection();
      
    • 在控制器中注入:IDeviceResolver deviceResolver

    • ...并通过deviceResolver.Device.Type获取设备信息,例如:

      var isMobile = deviceResolver.Device.Type == DeviceType.Mobile;
      var isDesktop = deviceResolver.Device.Type == DeviceType.Desktop;
      ...
      

    有关详细信息,请参阅documentation

    【讨论】:

    • 我不想要浏览器名称,我想要我的 web 应用程序在计算机浏览器或移动浏览器中运行的条件?
    • 我添加了一个使用ASP.NET Core Detection 库获取设备类型的示例。
    猜你喜欢
    • 2020-06-05
    • 2018-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-15
    相关资源
    最近更新 更多