Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7584373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:54:18+00:00 2026-05-30T18:54:18+00:00

I want to create multilingual URLs for my ASP.NET MVC 3 project. Non-default language

  • 0

I want to create multilingual URLs for my ASP.NET MVC 3 project.

Non-default language should be passed in URL as the first parameter using routing. Like /es/blog/some-blog-post-slug

English will be used as default language and require not to pass the language in URL. Like /blog/some-blog-post

I tried to do it with routing but either routing breaks or URL generation.

I tried many options with Routing, with custom routing.
Currently I have:

routes.MapRoute(
"", // Route name
"{lang}/{controller}/{action}/{slug}", // URL with parameters
new { controller = "Test", action = "Index", slug = UrlParameter.Optional }, // Parameter defaults
new { lang = "^[a-z]{2}$" }
);

routes.MapRoute(
"", // Route name
"{controller}/{action}/{slug}", // URL with parameters
new { controller = "Test", action = "Index", slug = UrlParameter.Optional } // Parameter defaults
);

In my test view I have:

@Url.RouteUrl(new { controller = "Test", action = "Details", slug = "some-blog-post-slug" })
<br />
@Url.RouteUrl(new { lang = "es", controller = "Test", action = "Details", slug = "some-blog-post-slug" })

When I open the test view from "http://localhost:19038/test/details/my-blog-post-one" URL I see in my browser:

/Test/Details/some-blog-post-slug 

/es/Test/Details/some-blog-post-slug

That’s pretty much what I need

But when I open the test view from "http://localhost:19038/es/test/details/my-blog-post-one" URL I see different URL generated:

/es/Test/Details/some-blog-post-slug 

/es/Test/Details/some-blog-post-slug

When I open "http://localhost:19038/en/test/details/my-blog-post-one" I get:

/en/Test/Details/some-blog-post-slug 

/es/Test/Details/some-blog-post-slug

And "http://localhost:19038/xx/test/details/my-blog-post-one" produces:

/xx/Test/Details/some-blog-post-slug 

/es/Test/Details/some-blog-post-slug

Why “xx” is appended? I don’t pass a language to the Razor HTML URL helper.
I also tried to use lang = “en” in controller’s default parameters – it didn’t help.

I could end up adding the language to all URLs, but I want the URLs with default (“en”) language to omit the language in URL, and if even someone passing “en” – redirect to the URL without the language,
and when URL is generated for “en” URL should not include it.

What is the right way to do such thing?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:54:19+00:00Added an answer on May 30, 2026 at 6:54 pm

    When you visit /xx/Test/Details/some-blog-post-slug ASP.NET MVC 3 adds {lang} with value xx to the route data, and that is taken into account when you invoke:

    @Url.RouteUrl(new { controller = "Test", action = "Details", slug = "some-blog-post-slug" })
    

    If you specify

    @Url.RouteUrl(new { lang = (string)null, controller = "Test", action = "Details", slug = "some-blog-post-slug" })
    

    Then it renders the value you expect, by using the alternate route with the missing lang resulting in:

    /Test/Details/some-blog-post-slug
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create Mysql data base in asp.net (c#) as Dynamically.My task is when
I want create some type of ASP.NET (C# 2.0) Metrics class to help monitor
I have an asp.net web application which I want have multilingual support now. For
I want create a ModelForm class where model is a parameter passed from the
I want create own SetupTypeDlg using wix default dialogs to show the disk costs
How can I make a website multilingual? I want to create a website and
I want create a div container with a message for first time visitors to
I want create project wide accessible storage for project/application settings. What i want to
I want create batch process to update files on android tablet (for non-experienced user)
I want create a excel with Apache POI in java and I must insert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.