Task:
In asp.Net Core 2 I want to determine in the server controller at runtime whether the client browser is a mobile device so that the user interface of the return view can be adjusted in advance.
Nuget Package
Wangkanai.Detection (free)
ASP.NET Core Detection service components for details about client device, browser, engine, platform, and crawler.
In the startup.cs file you have to insert the line in the area ConfigureServices (..)
// Add detection services. services.AddDetectionCore() .AddDevice();
|
Then you just have to use the Using under the controller class
using Wangkanai.Detection;
|
And then you can evaluate the client directly from the request.
var client_Browser = Request.Browser(); var client_Device = Request.Device(); var client_Engine = Request.Engine(); var client_Platform = Request.Platform();
|
Here is a screenshot of the values that can be determined with Wangkanai Detection.
Evaluation at runtime
According to the debugger
? |
Name |
Value |
Type |
◢ |
client_Browser |
{Wangkanai.Detection.Browser} |
Wangkanai.Detection.Browser |
Bits |
0 |
byte |
|
Feature |
null |
Wangkanai.Detection.Feature |
|
Maker |
null |
string |
|
Name |
null |
string |
|
Type |
Generic |
Wangkanai.Detection.BrowserType |
|
Version |
null |
Wangkanai.Detection.IVersion |
|
◢ |
client_Device |
{Wangkanai.Detection.Device} |
Wangkanai.Detection.Device |
Crawler |
false |
bool |
|
Type |
Desktop |
Wangkanai.Detection.DeviceType |
|
◢ |
client_Engine |
{Wangkanai.Detection.Engine} |
Wangkanai.Detection.Engine |
Maker |
null |
string |
|
Name |
null |
string |
|
Type |
WebKit |
Wangkanai.Detection.EngineType |
|
Version |
null |
Wangkanai.Detection.IVersion |
|
◢ |
client_Platform |
{Wangkanai.Detection.Platform} |
Wangkanai.Detection.Platform |
Bits |
0 |
byte |
|
Name |
null |
string |
|
Type |
Windows |
Wangkanai.Detection.PlatformType |
|
Version |
null |
Wangkanai.Detection.IVersion |