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 5841977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:57:30+00:00 2026-05-22T11:57:30+00:00

I have an ASP.NET MVC 3 site using a custom route for specifying the

  • 0

I have an ASP.NET MVC 3 site using a custom route for specifying the language in the URL like so:

routes.MapRoute("Default", "{culture}/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", culture = "en", id = UrlParameter.Optional });

My base controller then sets the current thread culture appropriately in its OnActionExecuting event like so:

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
    var culture = filterContext.RouteData.Values["culture"] ?? "en";
    var cultureInfo = CultureInfo.GetCultureInfo((string)culture);
    Thread.CurrentThread.CurrentCulture = cultureInfo;
    Thread.CurrentThread.CurrentUICulture = cultureInfo;
    base.OnActionExecuting(filterContext);
}

Wherever I need a locale-specific string in my view, I reference the resource appropriately:

<img src="@Url.Content(Resources.Paths.ChallengeLogo)" alt="@Resources.Strings.AltChallengeLogo" class="logo" />

However, for images, the URL (src=”…”) will follow a convention “~/Content/Culture/Images/Whatever.jpg”, and I’d rather not have to manually maintain a resource file for each image location. In short, what I’d prefer to do is:

<img src="@Url.Content("Images/ChallengeLogo.png")" alt="@Resources.Strings.AltChallengeLogo" class="logo" />

In this scenario, the Url.Content method would apply the path convention and translate the src attribute value to, for example:

/Content/en-US/Images/ChallengeLogo.png
/Content/en-GB/Images/ChallengeLogo.png
/Content/de/Images/ChallengeLogo.png
etc...

I don’t have to use Url.Content specifically. I’m more than willing to create an extension method for this purpose, but I’m not sure if I’m even taking the best approach. What is the standard approach here?

Edit: I ended up creating an helper. The helper has the added benefit of checking that the path to the current culture actually exists, or falling back to the parent / default culture if necessary. Code below:

private static CultureInfo _defaultCulture = CultureInfo.GetCultureInfo("en");

public static string Localized(this UrlHelper url, string pathTemplate)
{
    var server = url.RequestContext.HttpContext.Server;
    var culture = Thread.CurrentThread.CurrentUICulture;
    var localizedPath = string.Format(pathTemplate, culture.Name);
    var physicalPath = server.MapPath(localizedPath);

    while (!File.Exists(physicalPath) && culture.Parent != null)
    {
        culture = culture.Parent;
        localizedPath = string.Format(pathTemplate, culture.Name);
        physicalPath = server.MapPath(localizedPath);
    }

    if (!File.Exists(physicalPath))
        localizedPath = string.Format(pathTemplate, _defaultCulture.Name);

    return url.Content(localizedPath);
}

In my views, I can use this helper as follows:

<div class="toolbox">

    <a href="#" class="button register">
        <img src="@Url.Localized("~/Content/Localized/{0}/Images/Button_Register.png")" 
             alt="@Resources.Strings.AltRegisterButton" /></a>

    <a href="#" class="button login">
        <img src="@Url.Localized("~/Content/Localized/{0}/Images/Button_Login.png")" 
             alt="@Resources.Strings.AltLoginButton" /></a>

</div>
  • 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-22T11:57:31+00:00Added an answer on May 22, 2026 at 11:57 am

    I think your suggestion is the first one that came to my mind too.
    You can easily solve this with creating your own html helper that constructs the localized url. See http://develoq.net/2011/how-to-create-custom-html-helpers-for-asp-net-mvc-3-and-razor-view-engine/ as an example for creating a custom html helper.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
I've been developing a site using ASP.NET MVC, and have decided to use the
I am currently creating an e-commerce site using C# ASP.NET MVC and have just
I'm working on my first asp.net mvc application and I'm using custom helpers like
I have an Asp.net Mvc site where I want to give a separate access
I am building an Asp.net MVC site where I have a fast dedicated server
I have an ASP.NET MVC (Beta 1) website that I'm using themes with. When
Quick questions really. I am currently building a site using asp.net MVC and the
We have asp.net mvc 2 site which allows www and without any subdomain. For
I'm writing an ASP.NET MVC site where I'm using LINQ to SQL to access

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.