Skip to content

UsePathBase regex #40959

@Alerinos

Description

@Alerinos

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I need to add a regex in UsePathBase, I want to culture the entire URL

Describe the solution you'd like

I am using blazor server side.

I currently have something like this:

            app.UsePathBase("/pl");
            app.UsePathBase("/pl-pl");
            app.UsePathBase("/en");
            app.UsePathBase("/en-us");
            app.UsePathBase("/de");
            app.UsePathBase("/it");

Need:

app.UsePathBase("/{culture:regex(^[a-zA-Z]{{2}}(-[a-zA-Z+]{{2}})?$)}");

This creates many problems but solves the one I care about. Thanks to this, we can have a culture in each URL. e.g:
domain.com/en-us/register

                endpoints.MapGet("/{culture:regex(^[a-zA-Z]{{2}}(-[a-zA-Z+]{{2}})?$)=pl}/{**rest}", async context =>
                {
                    var culture = context.Request.RouteValues["culture"] ?? _website.Culture;
                    var rest = context.Request.RouteValues["rest"];

                    var option = new CookieOptions
                    {
                        Expires = DateTime.Now.AddYears(1)
                    };
                    context.Response.Cookies.Append("Culture", culture.ToString() ?? "", option);
                    await Task.CompletedTask;
                });

Unfortunately, when we use PathBase, this request will not be performed and it will not save the cookie culture. Do you have an idea how to do it?

The effect I want to get is written here:
#38584 (comment)

The problem of using app.UsePathBase is that a value is added to <base href = "~ /" />, so we need to change to <base href = "/" />

Additional context

Let me know what you think, in short I need to be able to prefix in the url. I need to support the culture as in the example in the link above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions