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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:14:12+00:00 2026-06-01T10:14:12+00:00

Sorry for asking a rather n00b question, I am rather new to ASP.NET MVC.

  • 0

Sorry for asking a rather n00b question, I am rather new to ASP.NET MVC.
My problem is as follows:

I want my site to handle a URL in the following way:

www.mysite.com/homepage/name

I want the above link to go to that user’s profile. For simplicity the controller will be the Homepage controller with the Test action.

Meaning that the global.asax routing will be:

routes.MapRoute(
            "test",
            "homepage/{name}",
            new { controller = "Homepage", action = "Test" }
            );

Up until now the code works great (I have tested it and it routes ok).

But now my other functionality which I want is to enable:

www.mysite.com/homepage/action/id

To work as well.

The routing for this will be:

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

The problem is what happens when a user wants to omit the {id} for an action, the routing table detects that the action name is actually the {name} parameter.

Is there any way to first CHECK if an action exists. And only if it doesn’t, then use it as a parameter for a different route.

Makes sense? if not I’ll add some more details.

Thanks!

EDIT

So I’ve managed to solve this using the constraints regex
I placed a regex defining a all the actions in my controller:

routes.MapRoute(
           "homepage",
           "homepage/{action}/{id}",
           new { controller = "Homepage", action = "Index", id = UrlParameter.Optional },
           new { action = "(action1|action2|action3)" }
           );

And then the next rule:

routes.MapRoute(
            "feed",
            "homepage/{id}",
            new { controller = "Homepage", action = "Test"}
            );

I works ok, only it’s hard to scale upon this. You need to remember to place every new action on the controller inside the string here. It’s a huge opening for debug nightmares.

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-06-01T10:14:13+00:00Added an answer on June 1, 2026 at 10:14 am

    You need to put the Default route first, and also restrict its allowed values

    routes.MapRoute(
                "Default",
                "homepage/{action}/{id}",
                new { controller = "Homepage", action = "Index", id = UrlParameter.Optional },
                new {action = @"Index|Delete|Add"}
            );
    
    routes.MapRoute(
                "test",
                "homepage/{name}",
                new { controller = "Homepage", action = "Test" }
                );
    

    This way the first route will only be used if the action value matches one provided in the constraint, otherwise it will move to the next rule.

    You will also have to make sure when you create user profiles, that no name should match one of your supported actions for the default route.

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

Sidebar

Related Questions

I am new to Cstring, sorry for asking dumb question, please help. char string[10];
Guys, sorry for asking basic question, i have a problem here where I have
Yeah, sorry about asking a stupid n00b question. So I have a C# program.
Sorry for asking a stupid question but I have a problem that makes me
sorry for asking this dumb question i will try to explain as good as
First off, I'm sorry for asking such a simple question in such a sophisticated
yes its a joomla question and im sorry to annoy but asking on the
Sorry for a long question and not a very descriptive title, but my problem
Sorry for asking this question, but I searched all Java-related questions, but I got
Sorry for asking what seems like such an obvious question. I have an adapter

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.