如何在blazor服务器端应用程序中检测移动设备?

问题描述:

我需要检测我的blazor服务器端应用程序的用户是否正在使用移动设备.有什么方法可以找出用户使用的设备吗?

I need to detect if the user of my blazor server side application is using a mobile device. Is there any way to find out which device the user is using?

我知道我可以使用JSRuntime做到这一点,但是有什么办法可以通过纯C#来解决它?

I know I can do it with a JSRuntime but is there any way to figure it out with pure C#?

我确实找到了这篇文章,可以阅读Blazor中一个窗口的宽度和高度.看起来它使用了JS Interop.这样,您可以根据其分辨率的宽度确定用户是否正在使用手机.当然,这并不是100%完全的证明,因为桌面上的某人可以将其窗口大小调整为移动分辨率. https://blazor.tips/blazor-how-to-ready-window-dimensions/

I did find this article that will read you the width and height of a window in Blazor. Looks like it uses JS Interop. With that, you can determine if a user is using a mobile based on the width of their resolution. Of course, it's not 100% full proof as someone on a desktop can resize their window down to a mobile resolution. https://blazor.tips/blazor-how-to-ready-window-dimensions/