How to detect a device

Atilla Rüstəmli 40 Reputation points
2024-06-27T20:25:13.6533333+00:00

Hi, I'm currently working on .net core web API project . There is a moment that I can't figure out. I had to detect the device which user used when signed in. I used "user-agent" first but this only says if its smartphone, Desktop etc. And only on Apple products says that it is Iphone or Mac air and so on. Is there better way to detect device?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,611 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,009 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,621 Reputation points
    2024-06-27T22:08:27.25+00:00

    no. the user agent while not reliable it is the only way. see:

    https://deviceatlas.com/blog/mobile-browser-user-agent-strings#:~:text=What%20is%20the%20User%2DAgent,system%20and%20its%20version%2C%20etc.

    for layout, responsive design has replaced device detection.

    note: asp.net used to support device detection via the user agent, but gave up on keeping it current.


  2. SurferOnWww 3,201 Reputation points
    2024-06-28T00:53:58.5866667+00:00

    Is there better way to detect device?

    Can the User-Agent Client Hints provide some of required information?

    User-Agent Client Hints API

    https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.