Search code examples
cookiesaspnetboilerplate

Possibility to ignore application path in language cookie


I need to generate the language cookie "Abp.Localization.CultureName" ignoring the application path.

I found in the source code this part:

    protected virtual void SetCultureToCookie(HttpContext context, string culture)
    {
        context.Response.SetCookie(
            new HttpCookie(_webLocalizationConfiguration.CookieName, culture)
            {
                Expires = Clock.Now.AddYears(2),
                Path = context.Request.ApplicationPath
            }
        );
    }

How can I override this?

Thx


Solution

  • Subclass CurrentCultureSetter to override:

    public class MyCurrentCultureSetter : CurrentCultureSetter
    {
        protected override void SetCultureToCookie(HttpContext context, string culture)
        {
            // ...
        }
    }
    

    And replace the service in your module's PreInitialize() method:

    Configuration.ReplaceService<ICurrentCultureSetter, MyCurrentCultureSetter>();