dotnet / dotnet/systemweb-adapters

Proposal to add IsBrowser to HttpCapabilitiesBase

Open
#684 3 comments 0 reactions 0 assignees View on GitHub
up for grabs
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.