Extension methods for configuring anonymous access in development environments.
public static class AnonymousAccessExtensions
IServiceCollection AddAnonymousAccessForDevelopment(this IServiceCollection services)Summary: Registers an authorization handler that allows anonymous access to all endpoints in Development mode.
Parameters:
services- The service collection.Returns: The service collection for method chaining.
Extension methods for Microsoft.AspNetCore.Http.IFormFile to simplify file handling in ASP.NET Core.
public static class FormFileExtensions
Task<byte[]> GetBytes(this IFormFile formFile)Summary: Converts an uploaded form file to a byte array.
Parameters:
formFile- The form file to convert.Returns: A task representing the asynchronous operation, containing the file contents as a byte array.
Extension methods for Microsoft.AspNetCore.Http.IHeaderDictionary to manage request correlation and identity headers.
public static class HeaderDictionaryExtensions
string AddCorrelationId(this IHeaderDictionary headers, string correlationId)Summary: Adds a correlation ID to the header dictionary.
Parameters:
headers- The headers.
correlationId- The correlation ID to add.Returns: The correlation ID that was added.
string GetCallingOnBehalfOfIdentity(this IHeaderDictionary headers)Summary: Gets the on-behalf-of identity from the x-on-behalf-of header.
Parameters:
headers- The headers.Returns: The on-behalf-of identity if present; otherwise, null.
Remarks: This header is used in scenarios where a service acts on behalf of a user or another service.
string GetOrAddCorrelationId(this IHeaderDictionary headers)Summary: Gets the correlation ID from the header, or generates and adds a new one if not found.
Parameters:
headers- The headers.Returns: The correlation ID for the request.
string GetOrAddRequestId(this IHeaderDictionary headers)Summary: Gets the request ID from the header, or generates and adds a new one if not found.
Parameters:
headers- The headers.Returns: The request ID for the request.
Extension methods for Microsoft.AspNetCore.Http.HttpContext to retrieve request correlation identifiers.
public static class HttpContextExExtensions
string GetCorrelationId(this HttpContext context)Summary: Gets the correlation ID from the request headers.
Parameters:
context- The HTTP context.Returns: The correlation ID if present in the request headers; otherwise, null.
string GetRequestId(this HttpContext context)Summary: Gets the request ID from the request headers.
Parameters:
context- The HTTP context.Returns: The request ID if present in the request headers; otherwise, null.
Extension methods for Microsoft.AspNetCore.Http.HttpRequest to retrieve raw request body content.
public static class HttpRequestExExtensions
Task<byte[]> GetRawBodyBytesAsync(this HttpRequest request)Summary: Retrieves the raw body as a byte array from the Request.Body stream.
Parameters:
request- The HTTP request instance.Returns: A task representing the asynchronous operation, containing the request body as a byte array.
Task<string> GetRawBodyStringAsync(this HttpRequest request, Encoding encoding = null)Summary: Retrieves the raw body as a string from the Request.Body stream.
Parameters:
request- The HTTP request instance.
encoding- The encoding to use for reading the stream. Defaults to UTF8 if not specified.Returns: A task representing the asynchronous operation, containing the request body as a string.
Defines well-known HTTP header names used throughout the REST API framework.
Remarks: These header names follow common conventions for distributed tracing, pagination, conditional requests, and identity propagation in microservice architectures.
public static class WellKnownHttpHeaders
string CallingIdentitySummary: The calling identity header name for tracking the authenticated user identity.
string ContinuationSummary: The continuation token header name for cursor-based pagination.
string CorrelationIdSummary: The correlation ID header name for distributed tracing across service boundaries.
string ETagSummary: The ETag header name for entity versioning and caching.
string FilenameSummary: The filename header name for file download operations.
string IfMatchSummary: The If-Match header name for conditional requests based on ETag.
string IfNoneMatchSummary: The If-None-Match header name for conditional requests based on ETag.
string MaxItemCountSummary: The maximum item count header name for pagination requests.
string OnBehalfOfSummary: The on-behalf-of header name for identity delegation in service-to-service calls.
string RequestIdSummary: The request ID header name for tracking individual requests.
string ValueSeparatorSummary: The standard separator for multiple header values.