I have an Blazor server Application and we need to set up an global route prefix that we can use to set specific data based on the prefix. Is there any solution for that?
Ex. We want this /company/{companyID}/ To be on Every route and have a Middleware or something similar to cath the companyID in.
endpoints.MapGet("/company/{companyID:regex(^[a-zA-Z]{{3,100}}(-[a-zA-Z+]{{3,100}})?$)}/{**rest}", async context =>
{
var companyID = context.Request.RouteValues["companyID"]?.ToString()?.ToLower() ?? "default";
var restPath = context.Request.RouteValues["rest"]?.ToString()?.ToLower();
// Here i do stuff with the CompanyID
// This is for now, but will redirect to /index without company/companyID. Here i just want to go on with the Ondex component and keep the url.
context.Response.Redirect(restPath == null ? "/" : $"/{restPath}");
});
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");