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 a ASP.NET MVC site using Membership Provider. I have trouble testing some
I am developing a site using asp.net MVC. I have used AJAX for paging,sorting
I've been developing a site using ASP.NET MVC, and have decided to use the
Using ASP.Net MVC on my Site.Master I have: <head runat=server> <title><asp:ContentPlaceHolder ID=TitleContent runat=server />
Some site I'm programming is using both ASP.NET MVC and WebForms. I have a
i have an asp.net mvc site and here is a dynamic tooltip using qTip
I'm building an ASP.NET MVC site using the ADO.NET Entity Framework. I have an
I have a ASP.NET MVC site that is locked down using Forms Authentication. The
i have an asp.net-mvc site with sqlserver backend and i am using membershipprovider for
I have planned to create the mobile site using ASP.NET MVC. So, there is

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.