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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:55:47+00:00 2026-06-02T08:55:47+00:00

very simple question but I couldn’t find an answer for this: I have the

  • 0

very simple question but I couldn’t find an answer for this:

I have the default {controller}/{action}/{id} pattern in my global.asax.

I need also something will give me something like http://www.example.com/microsoft or http://www.example.com/apple while Microsoft and apple are id stored in database. Using the default pattern would be: http://www.example.com/brands/detail/microsoft

any idea how the pattern should be?
i tried: {id} and set the controller and action to brands and detail it work to serve my need but ruins all others pattern.

thanks

  • 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-02T08:55:48+00:00Added an answer on June 2, 2026 at 8:55 am

    Your route order matters. So create a first route definition which handles all available controllers and then mention one which will handle the rest of the requests. There you will handle the www.yousite.com/apple kind of request

    routes.MapRoute("Default",  // Route name
                      "{controller}/{action}/{id}", // URL with parameters
                        new { controller = "Home", action = "Index", id = "" },
                        new { controller = new FromValuesListConstraint("Home", "Account","OtherOne") }
                    );
    
     // to handle personalize user url
    routes.MapRoute("user","{url}", new {controller="Home",action="Profile",url = "" });
    

    Now create a new class called FromValuesListContraint which inherit from IRouteConstraint

    public class FromValuesListConstraint : IRouteConstraint
    {
        private string[] _values;
    
        public FromValuesListConstraint(params string[] values)
        {
            this._values = values; 
        }
    
        public bool Match(HttpContextBase httpContext, Route route, string parameterName,
        RouteValueDictionary values, RouteDirection routeDirection)
        {
            // Get the value called "parameterName" from the
            // RouteValueDictionary called "value"
    
            string value = values[parameterName].ToString();
    
            // Return true is the list of allowed values contains
            // this value.
    
            for (int i = 0; i < _values.Length; i++)
                if (SContains(_values[i], value, StringComparison.OrdinalIgnoreCase ))
                    return true;
    
            return false;
        }    
    
        public bool SContains(string source, string toCheck, StringComparison comp)
        {
            return source.IndexOf(toCheck, comp) >= 0;
        }
    }
    

    Have your Profile action method in Home read the parameter value and get data from your database.

     public ActionResult Profile(string url)
     {
        //url variable will have apple or microsoft . You may get data from db and return a view now.
     }
    

    So whenever a request comes, It will check whether it is a controller available ( which you passed into the FromValuesListContraint class constructor in your first route definition), if available then it will go for that routing, else, it will go for the general (default) route mentioned as the second route.

    In this example, Home, Account and OtherOnes are my available controllers. whenever you add a new controller to your project, you want to add that to the constrctor of FromValuesListConstraint class constructor.

    Simply saying it works like Catching some specific exception and going to the general exception if none of them are caught! 🙂 (just an example to understand)

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

Sidebar

Related Questions

This looked like a very simple question but I couldn't find the answer. How
My question is very simple, but I couldn't find an answer. I'm sorry if
I searched a bit, but couldn't find an answer to this (probably very simple)
This is a very simple question, but I can't seem to find something about
This is a very simple question with a simple answer, but it is not
Maybe, it's very simple question but I couldn't get the answer. I've been searching
I have a simple question that I think someone will answer very fast, but
I am new to rails and have a very simple question but couldnt find
This is probably a very simple question but I have a confusion about the
This may be very simple question,But please help me. i wanted to know what

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.