简体   繁体   中英

the type or namespace name 'HttpBrowserCapabilitiesBase' does not exist in the namespace 'System.web' in .net core 2.2

I am getting the title error when I do the code in .netcore2.2 .

Following is my code,

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

HttpBrowserCapabilitiesBase in this keyword it showing me the title error.

While this code is working perfectly below the .netcore2.2. HttpBrowserCapabilitiesBase is the interface of System.web DLL below the .netcore2.2.

It means the updated .net framework this namespace is not exist now which namespace is work, that I am not getting.

Depending on which information you need, you could look that up in the headers (eg Request.Headers["User-Agent"] as shown here ) instead, or get it using a library like Device Detection .

Edit: Here is a tutorial for getting the device type information using the ASP.NET Core Detection library:

  • Install the Wangkanai.Detection NuGet package.
  • Add to the ConfigureServices method in your Startup.cs :

     services.AddDetection();
  • In the controller inject: IDeviceResolver deviceResolver

  • ... and get the device information via: deviceResolver.Device.Type , eg:

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

See the documentation for further information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM