Skip to content

Commit

Permalink
Modified AspNetCoreRequestAccessor to handle absensce of an HttpContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyButland authored and Migaroez committed Feb 19, 2025
1 parent 3a753f4 commit c198e19
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public AspNetCoreRequestAccessor(
public string? GetRequestValue(string name) => GetFormValue(name) ?? GetQueryStringValue(name);

/// <inheritdoc />
public string? GetQueryStringValue(string name) => _httpContextAccessor.GetRequiredHttpContext().Request.Query[name];
public string? GetQueryStringValue(string name) => _httpContextAccessor.HttpContext?.Request.Query[name];

/// <inheritdoc />
public Uri? GetRequestUrl() => _httpContextAccessor.HttpContext != null
Expand Down Expand Up @@ -86,8 +86,8 @@ internal void EnsureApplicationUrl() =>

private string? GetFormValue(string name)
{
HttpRequest request = _httpContextAccessor.GetRequiredHttpContext().Request;
if (!request.HasFormContentType)
HttpRequest? request = _httpContextAccessor.HttpContext?.Request;
if (request?.HasFormContentType is not true)
{
return null;
}
Expand Down

0 comments on commit c198e19

Please sign in to comment.