title: How to create localized url in .net core?
body: <p>I have implemented localization in my .net core app and I am using cookies to change the culture. Now I want that my current culture should also in url How can i achieve this.</p>
  
  <p>To change Url what i am doing is:-</p>
  
  <pre><code>      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          app.UseAuthentication();
          var locOptions = 
     app.ApplicationServices.GetService&lt;IOptions&lt;RequestLocalizationOptions&gt;&gt;();
  
  
          app.UseRequestLocalization(locOptions.Value);
  
          CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
          var culture = cultureInfo.Name;
  
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
  
          app.UseStaticFiles();
          app.UseSession();
  
          //configuring mvc routes...
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                 name: "areaRoute",
                 template: "{area:exists}/{controller}/{action}/{id?}",
                 defaults: new { controller = "Home", action = "Index" });
  
              routes.MapRoute(
                  name: "default",
                  template: "{culture}/{controller}/{action}/{id?}",
                  defaults: new { culture = culture, controller = "Home", action = "Index" });
          });
      }
  </code></pre>
  
  <p>I am getting the current culture from thread and passing it to my route but it is always showing the default culture in url. The culture in url is not changing when I am changing the culture using cookies. </p>
  
  <p>Any Help will be appreciated.</p>
  
  <p>Edit:- My Configure Services Looks like this:-</p>
  
  <p>'''</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
         {
          //add authentication before all services
    services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
              .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =&gt;
              {
                  options.AccessDeniedPath = "/Account/Forbidden";
                  options.LoginPath = "/Account/Login";
  
              });
  
          services.AddDistributedMemoryCache();
          services.AddSession(options =&gt;
          {
              options.IdleTimeout = TimeSpan.FromDays(30);//You can set Time   
          });
  
          //adding HttpContextAccessor middleware
          services.AddSingleton&lt;IHttpContextAccessor, HttpContextAccessor&gt;();
  
          services.AddRouting(options =&gt; options.LowercaseUrls = true);
  
  
          //configuration for multilanguage support
          services.AddLocalization();
  
          services.AddMvc()
    .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
    .AddDataAnnotationsLocalization();
  
          //       services.AddMvc()
          //.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
          //.AddDataAnnotationsLocalization();
  
          services.Configure&lt;RequestLocalizationOptions&gt;(options =&gt;
          {
              var supportedCultures = new[]
              {
                  new CultureInfo("de"),
                  new CultureInfo("en")
              };
  
              // CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
  
              options.DefaultRequestCulture = new RequestCulture(culture: "de", uiCulture: "de");
              options.SupportedCultures = supportedCultures;
              options.SupportedUICultures = supportedCultures;
              //options.RequestCultureProviders.Insert(0, new RouteValueRequestCultureProvider(supportedCultures));
  
  
              options.RequestCultureProviders = new List&lt;IRequestCultureProvider&gt;
      {
          new QueryStringRequestCultureProvider(),
          new CookieRequestCultureProvider()
      };
          });
  
  
  
          //adding other services...
          ConfigureBusinessServices(services);
      }
  </code></pre>
  
  <p>I have a language changing option in application. And I am doing it like this, In my view:-</p>
  
  <pre><code>@using Microsoft.AspNetCore.Builder
  @using Microsoft.AspNetCore.Http.Features
  @using Microsoft.AspNetCore.Localization
  @using Microsoft.AspNetCore.Mvc.Localization
  @using Microsoft.Extensions.Options
  
  @inject IViewLocalizer Localizer
  @inject IOptions&lt;RequestLocalizationOptions&gt; LocOptions
  
  @{
      var requestCulture = Context.Features.Get&lt;IRequestCultureFeature&gt;();
      var cultureItems = LocOptions.Value.SupportedUICultures
          .Select(c =&gt; new SelectListItem { Value = c.Name, Text = c.DisplayName })
          .ToList();
      var returnUrl = string.IsNullOrEmpty(Context.Request.Path) ? "~/" : $"~{Context.Request.Path.Value}";
  }
  
  &lt;div title="@Localizer["Request culture provider:"] @requestCulture?.Provider?.GetType().Name"&gt;
      &lt;form id="selectLanguage" asp-controller="Language"
            asp-action="ChangeLanguage" asp-route-returnUrl="@returnUrl"
            method="post" class="form-horizontal" role="form"&gt;
          &lt;label asp-for="@requestCulture.RequestCulture.UICulture.Name"&gt;@Localizer["Language:"]&lt;/label&gt; &lt;select name="culture"
                                                                                                                 onchange="this.form.submit();"
                                                                                                                 asp-for="@requestCulture.RequestCulture.UICulture.Name" asp-items="cultureItems"&gt;&lt;/select&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My Controller to change culture:-</p>
  
  <pre><code> [HttpPost]
          public IActionResult ChangeLanguage(string culture, string returnUrl)
          {
  
              ////_languageManager.ChangeCulture(model.culture, model.uiCulture);
              //_languageManager.ChangeCulture(culture, culture);
  
              Response.Cookies.Append(
      CookieRequestCultureProvider.DefaultCookieName,
      CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)),
      new CookieOptions { Expires = DateTimeOffset.UtcNow.AddYears(1) }
  );
  
  
              return LocalRedirect(returnUrl);
          }
  </code></pre>
  
  <p>The problem is when my application starts it is showing german culture by default also in url. but when i change my language to english. The culture is changing all my data with english language is shown but the url still shows German(de).</p>