简体   繁体   English

如何通过 Razor 页面使用 51 度移动设备检测?

[英]How Do I Use 51 Degrees Mobile Device Detection with a Razor Page?

I have an ASP.Net Core 5.0 web application that I need to detect mobile devices for.我有一个需要检测移动设备的 ASP.Net Core 5.0 web 应用程序。 I downloaded the 51 Degrees NuGet Package using the Visual Studio Nuget Package Manager, but I cannot figure out how to use it from a Razor Page and cannot find any examples of it being used with Razor Pages anywhere. I downloaded the 51 Degrees NuGet Package using the Visual Studio Nuget Package Manager, but I cannot figure out how to use it from a Razor Page and cannot find any examples of it being used with Razor Pages anywhere.

So far it looks like the best example I can find is at https://51degrees.com/developers/documentation/apis/netv32/tutorials/getting-started but it says "This tutorial assumes you are building this from within the 51Degrees Visual Studio solution."到目前为止,看起来我能找到的最好的例子是https://51degrees.com/developers/documentation/apis/netv32/tutorials/getting-started但它说“本教程假设您是从 51Degrees Visual工作室解决方案。” Like most people I already have a solution for my app which I need to use 51 Degrees with and cannot create a new 51Degrees Visual Studio solution.像大多数人一样,我已经为我的应用程序提供了一个解决方案,我需要使用 51 度,并且无法创建新的 51 度 Visual Studio 解决方案。 Plus, the example has way more code than I want to use.另外,该示例的代码比我想要使用的要多得多。 I want something that works like Request.Browser.IsMobileDevice without requiring more work.我想要像 Request.Browser.IsMobileDevice 这样的东西,而不需要更多的工作。

Hi @WannabePuppetMaster,嗨@WannabePuppetMaster,

51Degrees Device Detection solution can be used in similar manner as with AspNet MVC as described in this example . 51Degrees 设备检测解决方案可以以与本示例中描述的 AspNet MVC 类似的方式使用。

The main difference is where the Device Data is obtained and made available to a Page .主要区别在于获取Device Data并将其提供给Page的位置。 In MVC, the data is obtained in the Controller before passing to the View , while in Razor Page it will need to be obtained in the Page Model so that the Page can access it via the Model object. In MVC, the data is obtained in the Controller before passing to the View , while in Razor Page it will need to be obtained in the Page Model so that the Page can access it via the Model object.

You can find more details in this comment with examples.您可以通过示例在此评论中找到更多详细信息。

You can find more examples (in various languages) and information from the documentation .您可以从文档中找到更多示例(各种语言)和信息。 For .NET specific details, please see Language Specific section.对于 .NET 的具体细节,请参阅Language Specific部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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