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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:14:22+00:00 2026-05-10T18:14:22+00:00

I am trying to create a route with a Username… So the URL would

  • 0

I am trying to create a route with a Username…

So the URL would be mydomain.com/abrudtkhul (abrudtkhul being the username)

My application will have public profiles based on usernames (Ex: http://delicious.com/abrudtkuhl). I want to replicate this URL scheme.

How can I structure this in ASP.Net MVC? I am using Membership/Roles Providers too.

  • 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. 2026-05-10T18:14:23+00:00Added an answer on May 10, 2026 at 6:14 pm

    Here’s what you want to do, first define your route map:

    routes.MapRoute(              'Users',               '{username}',                new { controller = 'User', action='index', username=''}); 

    What this allows you to do is to setup the following convention:

    • Controller: User (the UserController type)
    • Action: Index (this is mapped to the Index method of UserController)
    • Username: This is the parameter for the Index method

    So when you request the url http://mydomain.com/javier this will be translated to the call for UserController.Index(string username) where username is set to the value of javier.

    Now since you’re planning on using the MembershipProvider classes, you want to something more like this:

     public ActionResult Index(MembershipUser usr)  {     ViewData['Welcome'] = 'Viewing ' + usr.UserName;      return View();  } 

    In order to do this, you will need to use a ModelBinder to do the work of, well, binding from a username to a MembershipUser type. To do this, you will need to create your own ModelBinder type and apply it to the user parameter of the Index method. Your class can look something like this:

    public class UserBinder : IModelBinder {    public ModelBinderResult BindModel(ModelBindingContext bindingContext)    {       var request = bindingContext.HttpContext.Request;       var username = request['username'];       MembershipUser user = Membership.GetUser(username);        return new ModelBinderResult(user);    } } 

    This allows you to change the declaration of the Index method to be:

    public ActionResult Index([ModelBinder(typeof(UserBinder))]      MembershipUser usr) {     ViewData['Welcome'] = 'Viewing ' + usr.Username;     return View(); } 

    As you can see, we’ve applied the [ModelBinder(typeof(UserBinder))] attribute to the method’s parameter. This means that before your method is called the logic of your UserBinder type will be called so by the time the method gets called you will have a valid instance of your MembershipUser type.

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

Sidebar

Related Questions

I'm trying to create a snippet of regex that will match a URL route.
I'm trying to create a url pattern that will behave like controller/action/id route in
I'm trying to create a route in Kohana 3.2 that would match URIs like
I am trying to create an action ( :my_action ) route that will allow
I'm trying to create a Route in Cakephp that can have anything as a
I am trying to create a form in my view that will route to
I'm trying to create a route and then programatically retrieve the url of that
I'm trying to develop a cross platform application, where the most obvious route would
I am trying to create a route constraint but not sure what would be
im trying to create a simple private messaging system i have a nested route

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.