0

I have an ASP.Net Core 5.0 web application that I need to detect mobile devices for. 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." 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. 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.

  • https://stackoverflow.com/questions/13086856/mobile-device-detection-in-asp-net/13086894 detecting mobile device resolves mainly around parsing the "HTTP_USER_AGENT" – Charles Dec 27 '21 at 21:35
  • I know and I've ghetto rigged my own in the past, but I want something more reliable which is why I am trying to use 51 – WannabePuppetMaster Dec 27 '21 at 22:23
  • You want more dependencies in your projects? – Charles Dec 27 '21 at 22:33
  • Well, so far I've got it working somewhat but sometimes I get an error saying: InvalidOperationException: This instance has already started one or more requests. Properties can only be modified before sending the first request. System.Net.Http.HttpClient.CheckDisposedOrStarted() – WannabePuppetMaster Dec 27 '21 at 23:12

1 Answers1

0

Hi @WannabePuppetMaster,

51Degrees Device Detection solution can be used in similar manner as with AspNet MVC as described in this example.

The main difference is where the Device Data is obtained and made available to a 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.

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.

Tung Pham
  • 79
  • 6