-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathHttpContextExtensions.cs
More file actions
36 lines (30 loc) · 1019 Bytes
/
HttpContextExtensions.cs
File metadata and controls
36 lines (30 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright © https://myCSharp.de - all rights reserved
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
using MyCSharp.HttpUserAgentParser.AspNetCore.Telemetry;
namespace MyCSharp.HttpUserAgentParser.AspNetCore;
/// <summary>
/// Static extensions for <see cref="HttpContext"/>
/// </summary>
public static class HttpContextExtensions
{
/// <summary>
/// Returns the User-Agent header value
/// </summary>
public static string? GetUserAgentString(this HttpContext httpContext)
{
if (httpContext.Request.Headers.TryGetValue("User-Agent", out StringValues value))
{
if (HttpUserAgentParserAspNetCoreTelemetry.IsEnabled)
{
HttpUserAgentParserAspNetCoreTelemetry.UserAgentPresent();
}
return value;
}
if (HttpUserAgentParserAspNetCoreTelemetry.IsEnabled)
{
HttpUserAgentParserAspNetCoreTelemetry.UserAgentMissing();
}
return null;
}
}