diff --git a/BrowserDetector.sln b/BrowserDetector.sln index a0a1b0e..a52935f 100644 --- a/BrowserDetector.sln +++ b/BrowserDetector.sln @@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserDetector.Benchmarks" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserDetector.Net", "src\BrowserDetector.NetCore\BrowserDetector.Net.csproj", "{2E0D3C7A-98AA-475A-816B-3B51EA377C6A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserDetector.WebApi", "sample\BrowserDetector.WebApi\BrowserDetector.WebApi.csproj", "{6369627B-5878-4CFE-A996-859D8663603C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserDetector.WebApi", "sample\BrowserDetector.WebApi\BrowserDetector.WebApi.csproj", "{6369627B-5878-4CFE-A996-859D8663603C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{31BD75C3-015A-4308-9B08-07786C191BAC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/README.md b/README.md index 0f0cc76..60d8991 100644 --- a/README.md +++ b/README.md @@ -58,20 +58,14 @@ Install the [BrowserDetector nuget package](https://www.nuget.org/packages/Shyju Install-Package Shyjus.BrowserDetector ```` -**Step 2:** Enable the browser detection service inside the `ConfigureServices` method of `Startup.cs`. +**Step 2:** Enable the browser detection service by calling `AddBrowserDetection` method on `IServiceCollection` in your startup code. ```` -public void ConfigureServices(IServiceCollection services) -{ - // Add browser detection service - services.AddBrowserDetection(); - - services.AddMvc(); -} +services.AddBrowserDetection(); ```` **Step 3:** Inject `IBrowserDetector` to your controller class or view file or middleware and access the `Browser` property. -Example usage in controller code +#### Example usage in controller code ```` public class HomeController : Controller @@ -91,7 +85,7 @@ public class HomeController : Controller } ```` -Example usage in view code +#### Example usage in view code ```` @inject Shyjus.BrowserDetection.IBrowserDetector browserDetector @@ -103,7 +97,7 @@ Example usage in view code ```` -Example usage in custom middlware +#### Example usage in custom middleware You can inject the `IBrowserDetector` to the `InvokeAsync` method. diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..6fc4323 --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,95 @@ + +# BrowserDetector + +Browser detection capabilities for asp.net core. + + + +This library does + +1. Browser detection +2. Device type detection +3. Operating System detection + +**Step 1:** +Install the [BrowserDetector nuget package](https://www.nuget.org/packages/Shyjus.BrowserDetector/) + + +```` +Install-Package Shyjus.BrowserDetector +```` + +**Step 2:** Enable the browser detection service by calling `AddBrowserDetection` method on `IServiceCollection` in your startup code. + +```` +services.AddBrowserDetection(); +```` +**Step 3:** Inject `IBrowserDetector` to your controller class or view file or middleware and access the `Browser` property. + +### Example usage in controller code + +```` +public class HomeController : Controller +{ + private readonly IBrowserDetector browserDetector; + public HomeController(IBrowserDetector browserDetector) + { + this.browserDetector = browserDetector; + } + public IActionResult Index() + { + var browser = this.browserDetector.Browser; + // Use browser object as needed. + + return View(); + } +} +```` + +### Example usage in view code + +```` +@inject Shyjus.BrowserDetection.IBrowserDetector browserDetector + +

@browserDetector.Browser.Name

+

@browserDetector.Browser.Version

+

@browserDetector.Browser.OS

+

@browserDetector.Browser.DeviceType

+ +```` + +### Example usage in custom middleware + +You can inject the `IBrowserDetector` to the `InvokeAsync` method. + +```` +public class MyCustomMiddleware +{ + private RequestDelegate next; + public MyCustomMiddleware(RequestDelegate next) + { + this.next = next; + } + public async Task InvokeAsync(HttpContext httpContext, IBrowserDetector browserDetector) + { + var browser = browserDetector.Browser; + + if (browser.Type == BrowserType.Edge) + { + await httpContext.Response.WriteAsync("Have you tried the new chromuim based edge ?"); + } + else + { + await this.next.Invoke(httpContext); + } + } +} +```` + +### Interpreting the `Name` value returned by `IBrowser.Name` + + * Firefox - Firefox browser. + * EdgeChromium - The new Chromium based Microsoft Edge browser. + * Edge - The legacy Edge browser. + * Safari - The Safari browser. + * Chrome - The Chrome browser. \ No newline at end of file diff --git a/src/BrowserDetector.NetCore/BrowserDetector.Net.csproj b/src/BrowserDetector.NetCore/BrowserDetector.Net.csproj index 184235c..ee6ad2a 100644 --- a/src/BrowserDetector.NetCore/BrowserDetector.Net.csproj +++ b/src/BrowserDetector.NetCore/BrowserDetector.Net.csproj @@ -2,19 +2,22 @@ net6.0;net7.0;net8.0 - Shyjus.BrowserDetector - Shyjus.BrowserDetector - Shyjus.BrowserDetector - Shyju Krishnankutty - Browser detection, device detection and operating system detection capabilities in asp.net core. - https://github.com/kshyju/BrowserDetector - BrowserDetection BrowserCapabilities BrowserDetectionASP.NETCore HttpContext.Request.Browser DeviceDetection - true - 2.0.1-preview1 + Shyjus.BrowserDetector + Shyjus.BrowserDetector + Shyjus.BrowserDetector + Shyju Krishnankutty + Browser detection, device detection and operating system detection capabilities in asp.net core. + https://github.com/kshyju/BrowserDetector + BrowserDetection BrowserCapabilities BrowserDetectionASP.NETCore HttpContext.Request.Browser DeviceDetection + true + readme.md + 2.0.1-preview1 - + + +