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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:05:50+00:00 2026-05-23T13:05:50+00:00

I want to map a route like this: mysite.com/username in ASP.NET MVC 3 application;

  • 0

I want to map a route like this:

mysite.com/username

in ASP.NET MVC 3 application; How can I do it, please?
Thanks to all, regards

  • 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-23T13:05:50+00:00Added an answer on May 23, 2026 at 1:05 pm

    Maybe add custom route at the very beginning that would inherit from System.Web.Routing.Route, and override method

    protected virtual bool ProcessConstraint(HttpContextBase httpContext, object constraint, 
       string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
    

    where you would check in db using indexed column.

    Just add some not nullable constraint object like

    Constraints = new { username = "*" }
    

    so that route object will process constraints.

    Before hitting database maybe make some heuristics whether this can be username. Remember you cant have user same as controller (when having default action), so you want to limit that somehow. Pay attention if that wont hurt year performance, but you probably dont have many routes with single value after slash.

    This is how you can do this.

    public class UserRoute : Route
    {
        public UserRoute(string url, RouteValueDictionary defaults, RouteValueDictionary constraints, IRouteHandler routeHandler)
            : base(url, defaults, constraints, routeHandler)
        {
        }
    
        protected override bool ProcessConstraint(HttpContextBase httpContext, object constraint, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            if (routeDirection == RouteDirection.UrlGeneration)
                return true;
    
            object value;
            values.TryGetValue(parameterName, out value);
            string input = Convert.ToString(value, CultureInfo.InvariantCulture);
            // check db
            if (!CheckHeuristicIfCanBeUserName(input))
            {
                return false;
            }
    
            // check in db if exists, 
            // if yes then return true
            // if not return false - so that processing of routing goes further
            return new[] {"Javad_Amiry", "llapinski"}.Contains(input);
        }
    
        private bool CheckHeuristicIfCanBeUserName(string input)
        {
            return !string.IsNullOrEmpty(input);
        }
    }
    

    This add at the beginning.

    routes.Add(new UserRoute("{username}", 
                new RouteValueDictionary(){ {"controller", "Home"}, {"action", "About"}}, 
                new RouteValueDictionary(){ { "username", "*" }}, new MvcRouteHandler()));
    

    Works for me in both ways, generating and incomming.

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

Sidebar

Related Questions

Say I want to display user details like so: http://www.mysite.com/user/1 I set a route
I am working with ASP.NET MVC 2 and would like to optimize my routing.
When we search route through Google Map web site, like this route: http://goo.gl/maps/2mg8 Google
I want to open an inbuilt google map intent to show route between two
I want to map DbConnection to an un-opened SqlConnection using Ninject . This is
I have this route: # config/routes.rb map.namespace :backshop, :path_prefix => '/:shop_id/admin' do |backshop| backshop.resources
I currently have a routes.rb file that looks like this: map.resources :profiles do |profile|
I have a route that looks like the following: map.newsletter '/newsletter', :controller => newsletter
I know how to setup a route to a url like http://siteurl.com/mycustomaccount/dashboard , but
i've integrated a map and i want to display the route directions between two

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.