# Detection **Repository Path**: leeolevis/Detection ## Basic Information - **Project Name**: Detection - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-31 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ASP.NET Core Detection [](https://opencollective.com/wangkanai) [](https://ci.appveyor.com/project/wangkanai/detection) - **Wangkanai.Detection** [](https://www.nuget.org/packages/wangkanai.detection) [](https://www.nuget.org/packages/wangkanai.detection) [](https://www.myget.org/feed/wangkanai/package/nuget/Wangkanai.detection) - **Wangkanai.Responsive** [](https://www.nuget.org/packages/wangkanai.detection) [](https://www.nuget.org/packages/wangkanai.Responsive) [](https://www.myget.org/feed/wangkanai/package/nuget/Wangkanai.Responsive) [](https://ci.appveyor.com/project/wangkanai/detection/history) ASP.NET Core client web browser detection extension to resolve devices, platforms, engine of the client. ASP.NET Core Responsive middleware for routing base upon request client device detection to specific view  ## Installation Installation of detection library is now done with a single package reference point. ```powershell PM> install-package Wangkanai.Detection ``` Installation of Responsive library will bring in all dependency packages (This will include `Wangkanai.Detection.Device). ```powershell PM> install-package Wangkanai.Responsive ``` ## Configuration This library host the component to resolve the access client device type. Implement of the library into your web application is done by configuring the `Startup.cs` by adding the detection service in the `ConfigureServices` method. ```csharp public void ConfigureServices(IServiceCollection services) { // Add detection services container and device resolver service. services.AddDetection(); // Add framework services. services.AddMvc(); } ``` * `AddDetection()` Adds the detection services to the services container. If you would like to add Responsive is configured in the `ConfigureServices` method also: ```csharp public void ConfigureServices(IServiceCollection services) { // Add responsive services. services.AddResponsive(); // Add framework services. services.AddMvc(); } ``` Or you can customize the responsive ```csharp public void ConfigureServices(IServiceCollection services) { // Add responsive services. services.AddResponsive(options => { options.View.DefaultTablet = DeviceType.Desktop; options.View.DefaultMobile = DeviceType.Desktop; options.View.DefaultDesktop = DeviceType.Desktop; }); // Add framework services. services.AddMvc(); } ``` * `AddResponsive()` Adds the Responsive services to the services container. * **Suffix** Ex `*views/[controller]/[action]/index.mobile.cshtml*` * **SubFoler** Ex `*views/[controller]/[action]/mobile/index.cshtml*` The current device on a request is set in the Responsive middleware. The Responsive middleware is enabled in the `Configure` method of *Startup.cs* file. ```csharp public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { app.UseResponsive(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } ``` ## Global Resolver This library host the component to resolve all the access client related resolver that could resolve. Example of calling the detection service in the `Controller` using dependency injection. ```csharp public class HomeController : Controller { private readonly IDetection _detection; public HomeController(IDetection detection) { _detection = detection; } public IActionResult Index() { return View(_detection); } } ``` * `IDetection` is main service for you to access detection service. When the `Detection` is pass to the view you can render results like the following example. ```html @model Wangkanai.Detection.Detection
@Model.UserAgent
| Resolver | Type | Version |
|---|---|---|
| Device | @Model.Device?.Type.ToString() | |
| Browser | @Model.Browser?.Type.ToString() | @Model.Browser?.Version |
| Platform | @Model.Platform?.Type.ToString() | @Model.Platform?.Version |
| Engine | @Model.Engine?.Type.ToString() | @Model.Engine?.Version |
| Crawler | @Model.Crawler?.Type.ToString() | @Model.Crawler?.Version |