mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 16:38:37 +00:00
Add ability to determine if a request originated from a mobile device
This commit is contained in:
parent
6817c3089e
commit
024d5eff90
1 changed files with 15 additions and 0 deletions
15
ProjectLighthouse/Helpers/Extensions/RequestExtensions.cs
Normal file
15
ProjectLighthouse/Helpers/Extensions/RequestExtensions.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions
|
||||
{
|
||||
// yoinked and adapted from https://stackoverflow.com/a/68641796
|
||||
public static class RequestExtensions
|
||||
{
|
||||
private static readonly Regex mobileCheck = new
|
||||
("Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
|
||||
|
||||
public static bool IsMobile(this HttpRequest request) => mobileCheck.IsMatch(request.Headers[HeaderNames.UserAgent].ToString());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue