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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:34:48+00:00 2026-06-09T02:34:48+00:00

I have been looking at several pages on here already such as: How do

  • 0

I have been looking at several pages on here already such as:

How do I redirect to the previous action in ASP.NET MVC?

How can I redirect my action to the root of the web site?

Along with several hours of searching google.

No where seems to have an answer to my problem and I am sure it should be possible within MVC somehow hence the reason I am now here to ask the question.

So the problem I am facing is that I want to allow the user to change the language of the page by choosing a new language from a drop down menu which is in its own partial view hence the problem, I need to redirect to the parent action and not the child. This all works fine as long as i send the user back to the root of the site. Using the following code:

  [HttpPost]
    public ActionResult RegionSelect(RegionSelectionModel model)
    {
        var currentUser = Session.GetCurrentUser();
        var currentDbUser = Session.GetUserEntity(_dataAccessLayer);
        if (!ModelState.IsValid)
        {
            model.AvailableRegions = CacheHelpers.GetAvailableRegions<RegionView>(_dataAccessLayer, _cache).ToList();
            return PartialView("_RegionSelect", model);
        }

        var selectedRegion = UsersControllerHelpers.SetSelectedRegion(model, _dataAccessLayer, _cache, _website.Client);
        var uri = model.OriginalUrl;
        var routeInfo = new RouteHelpers(uri, HttpContext.Request.ApplicationPath);

        // Route Data  
        var routeData = routeInfo.RouteData;

        routeData.Values.Remove("language");

        var defaultClientLanguageCode = _website.Client.LanguagesSupported.FirstOrDefault().Code;
        if (currentDbUser.Language.CountryCode != selectedRegion.PrimaryLanguage.CountryCode)
        {
            //TODO: Decide where to redirect or whether to refresh the whole page...
            if ((defaultClientLanguageCode == selectedRegion.PrimaryLanguage.CountryCode) || (model.SelectedRegionId == 0))
            {
                UsersControllerHelpers.UpdateUsersRegions(currentUser, selectedRegion, _website.Client, _cache, _dataAccessLayer,
                                                          Session);
                return RedirectToRoute(routeData.Values);
            }

            routeData.Values.Add("language",selectedRegion.PrimaryLanguage.CountryCode);
            return RedirectToRoute(routeData.Values);
        }

        return RedirectToRoute(routeData.Values);
    }

Two of my return statements return to the root page and one returns to the root but with a language so it would be “http://mysite/en-En/” but what if the user is on a page other than the root site? I want to somehow redirect them back to this same action but with the correct language string at the start.

How can i do this?

I have thought of several “hacky” ways of doing this, such as splitting the URL and swapping the language codes over. But ideally I am looking to do this as clean as possible.

Can anyone give me any idea’s? Or is it just not possible?

It seems like it should be really simple but apparently not.

Thanks in advance for any help that you can provide.

EDITED

Added new code that is using code from suggested answer below.

I am now having two new problems.

  1. I am getting this error message, if there are any things in the URL such as ?page=1:
    A potentially dangerous Request.Path value was detected from the client (?)

  2. If i try and remove the language completely using .Remove(). It removes it fine but when i try and redirect to the page in the default language it adds language?=language to the end of the URI.

Any ideas how i can resolve these two issues?

  • 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-06-09T02:34:50+00:00Added an answer on June 9, 2026 at 2:34 am

    This option is definitely my answer. Leave me a comment if you need me to drop some code, and I can do that, but the examples on the linked website should get you started.

    Use this method to change Request.UrlReferrer into Route data, then merge your language into that, then do a RedirectToRoute with the modified Route data.

    Just use RouteData.Values.Add, RouteData.Values.Remove, and RouteData.values[“whatever”], then pass that modified RouteData.Values object to RedirectToRoute()

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

Sidebar

Related Questions

I have been looking into backbone.js and I can't seem to figure out how
Background: I work in a suite of ASP.NET applications that have several different modules.
I have been looking around online for an answer to this question for several
We have an asp.net web site that is deployed on several IIS servers. The
I have been looking at several deployment strategies for SSIS and wondering which one
I have been looking over several examples of backgroundworkers and I ran across code
I'm a django newbie and have been looking at this timezone stuff for several
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking around for a visualization framework that would aid graph visualization
I have been looking online to find documentation for the function in QTP and

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.