Created
May 9, 2023 19:05
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RequestCultureMiddleware | |
{ | |
private readonly RequestDelegate _next; | |
public RequestCultureMiddleware(RequestDelegate next) | |
{ | |
_next = next; | |
} | |
public async Task InvokeAsync(HttpContext context) | |
{ | |
var cultureQuery = context.Request.Query["culture"]; | |
if (!string.IsNullOrWhiteSpace(cultureQuery)) | |
{ | |
var culture = new CultureInfo(cultureQuery); | |
CultureInfo.CurrentCulture = culture; | |
CultureInfo.CurrentUICulture = culture; | |
} | |
// Call the next delegate/middleware in the pipeline. | |
await _next(context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment