dotnet / dotnet/systemweb-adapters
Proposal to add IsBrowser to HttpCapabilitiesBase
- Dominant language
- C#
- Stars
- 384
- Forks
- 76
- Avg merge
- 2h 24m
- Merged PRs (30d)
- 1
Description
## Summary
Add `bool IsBrowser(string browserName)` method to [HttpCapabilitiesBase.cs](https://github.com/dotnet/systemweb-adapters/blob/main/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs). For our use case it would be enough to just have
```
public bool IsBrowser(string browserName) => string.Equals(Browser, browserName, StringComparison.OrdinalIgnoreCase);
```
in `HttpCapabilitiesBase`.
But as I have understood the [original implementation](https://github.com/microsoft/referencesource/blob/main/System.Web/Configuration/HttpCapabilitiesBase.cs#L1748) is hierarchical so that when running Chrome these all would return true
```
IsBrowser("Default")
IsBrowser("Mozilla")
IsBrowser("WebKit")
IsBrowser("Chrome")
```
Which approach would you like to go with?
## Motivation and goals
We are migrating an ASP.NET application to [CoreWebForms](https://github.com/CoreWebForms/CoreWebForms). We use [Telerik UI](https://www.telerik.com/products/aspnet-ajax/documentation/introduction) and some of their components such as `RadAjaxLoadingPanel` depends on using `System.Web.Configuration.HttpCapabilitiesBase.IsBrowser(System.String)` to check if the user is running on IE 7. Adding `IsBrowser` to `HttpCapabilitiesBase` would help us greatly with the migration.
Example:
```
System.MissingMethodException: Method not found: 'Boolean System.Web.Configuration.HttpCapabilitiesBase.IsBrowser(System.String)'.
at Telerik.Web.SkinRegistrar.RegisterStyleSheetReference(ISkinnableControl control, StyleSheetReference reference, StringBuilder cssRegs, Type controlToRegisterType)
```
## In scope
- `public bool IsBrowser(string browserName)` method to `HttpCapabilitiesBase`
Optionally:
- Implement `AddBrowser(string browser)` at [BrowserCapabilitiesFactory](https://github.com/dotnet/systemweb-adapters/blob/main/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/BrowserCapabilitiesFactory.cs#L662) to allow hierarchical matching
- Unit tests for hierarchical matching
## Out of scope
Optionally hierarchical matching
## Risks / unknowns
Not implementing hierarchical matching can cause code to silently take another path when using SystemWeb Adapters
## Examples
```
HttpContext.Current.Request.Browser.IsBrowser("IE")
```
Contributor guide
Assessment
This issue has not been assessed yet.