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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:34:48+00:00 2026-05-15T22:34:48+00:00

Currently, I have URLs that look like this: http://www.example.com/user/create http://www.example.com/user/edit/1 But now, I have

  • 0

Currently, I have URLs that look like this:

http://www.example.com/user/create
http://www.example.com/user/edit/1

But now, I have to support multiple organizations and their users. I need to have something like this:

http://www.example.com/org-name/user/create
http://www.example.com/org-name/user/edit/1

I was having trouble getting the routes to work just perfectly, so I had to add a token to the beginning of the organization name so that routing wouldn’t confuse it with a controller/action pair. Not a huge deal but my URLs look like this now:

http://www.example.com/o/org-name/user/create
http://www.example.com/o/org-name/user/edit/1

That’s fine. I can live with that.

Here’s where I’m running into trouble:
When I generate URLs once I have an organization selected, it’s not persisting the organization name. So when I’m here:

http://www.example.com/o/org-name

…and I use Url.Action(“User”, “Create”) to generate a URL, it outputs:

/user/create

…rather than what I want:

/o/org-name/user/create

This is what my routes look like (in order):

        routes.MapRouteLowercase(
            "DefaultOrganization",
            "{token}/{organization}/{controller}/{action}/{id}",
            new { id = UrlParameter.Optional },
            new { token = "o" }
        );

        routes.MapRouteLowercase(
            "OrganizationDashboard",
            "{token}/{organization}/{controller}",
            new { controller = "Organization", action = "Dashboard" },
            new { token = "o" }
        );

        routes.MapRouteLowercase(
            "DefaultSansOrganization",
            "{controller}/{action}/{id}",
            new { controller = "Core", action="Dashboard", id = UrlParameter.Optional }
        );

It’s similar to this question ASP.NET MVC Custom Routing Long Custom Route not Clicking in my Head.

I have a feeling this is going to end up being obvious but it’s Friday and it’s not happening right now.

EDIT:
Womp’s suggested worked but would this be the best way to automate this?

public static string ActionPrepend(this UrlHelper helper, string actionName, string controllerName)
    {
        string currentUrl = helper.RequestContext.RouteData.Values["url"] as string;
        string actionUrl = string.Empty;

        if (currentUrl != null)
        {
            Uri url = new Uri(currentUrl);

            if (url.Segments.Length > 2 && url.Segments[1] == "o/")
                actionUrl = string.Format("{0}{1}{2}{3}", url.Segments[0], url.Segments[1], url.Segments[2],
                    helper.Action(actionName, controllerName));
        }

        if(string.IsNullOrEmpty(actionUrl))
            actionUrl = helper.Action(actionName, controllerName);

        return actionUrl;
    }

EDIT:
Fixed my routes to work rather than hacking it together. The final solution didn’t need the stupid {token} in the URL. Maybe this’ll help someone else:

routes.MapRouteLowercase(
    "Organization",
    "{organization}/{controller}/{action}/{id}",
    new { controller = "Organization", action = "Dashboard", id = UrlParameter.Optional },
    new { organization = @"^(?!User|Account|Report).*$" }
);

routes.MapRouteLowercase(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Core", action = "Dashboard", id = UrlParameter.Optional }
);
  • 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-15T22:34:49+00:00Added an answer on May 15, 2026 at 10:34 pm

    Url.Action uses route values to generate the actual URL’s by querying the virtual path provider and attempting to match the most specific route. In the form that you are using, you are supplying values for the controller and the action, which is as deep as most simple websites go, hence the convenient form of the method. When Url.Action queries the routing system, it only has a “controller” and an “action” segment to match.

    If you give the method the rest of the routing information it needs, it will properly match the route that you desire, and will return the correct URL. Try this:

    Url.Action("User", "Create", new { token = "o", organization = "organization" })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
I have some mod_rewrite rewrites that correctly redirect the URLs to a script. From
I receive a list of image URLs and currently I have several hidden img
I currently have an MS Access application that connects to a PostgreSQL database via
I currently have a fairly robust server-side validation system in place, but I'm looking
I currently have a class and I'm trying to create an easy GUI to
I've got a list that looks like this: <li class = current_parent level-0> <a>
I currently have speakers set up both in my office and in my living
I currently have an existing database and I am using the LINQtoSQL generator tool
We currently have a company email server with Exchange, and a bulk email processing

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.