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

  • Home
  • SEARCH
  • 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 url pattern that will behave like controller/action/id route in
I'm trying to create a route and then programatically retrieve the url of that
I am trying to create an action ( :my_action ) route that will allow
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
Trying to create my first iPhone app that would play back audio. When I
Trying to create a small monitor application that displays current internet usage as percentage
I'm trying to create a nested resource with a url scheme along the lines
I have a web application which will return a user id based on the
I'm trying to create a route to a specific controller/action which needs to accept
I'm trying to create an ASP.NET MVC2 route with a regular expression constraint to

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.