MVC MapRoute with username

I'm building a small MVC application. After a user logs in I want his/her route to display:

Underneath of course same action is called for each user e.g. /home/index. How do I write my MapRoute to achieve that and what other code(attributes) should I use?

-------------Problems Reply------------

Add this rout to your routes in global.asax.cs file

"RouteName", // Route name
"FixedUrlSegment/{UserName}/{Controller}/{action}/{id}/", // URL with parameters
new { controller = "ControllerName",
action = "ActionName",

I think you should use a fixed segment as start-up point for your route to distinguish it from default or other routes

of course in log in action method you must redirect to that new route

return RedirectToRoutePermanent("RouteName", new { username = "UserName",
action = "Index",
controller = "Home",
// remember id is not required for that route as mentioned in global file

this example will redirect your page to url mvc Views:8 Time:2012-03-25

Related post

  • ASP.Net MVC Route to Username 2008-10-24

    I am trying to create a route with a Username... So the URL would be (abrudtkhul being the username) My application will have public profiles based on usernames (Ex: I want to replicate this U

  • ASP.NET MVC - MapRoute versus routes.Add (and 404s) 2009-02-04

    I'm just getting started with ASP.NET MVC. What is the difference between MapRoute and routes.Add ? Should I just be using MapRoute? Can I map multiple routes? Which "maps" take precedence... those you called first or last? I'd like to be able to do

  • ASP.Net MVC MapRoute problem 2009-03-31

    There seem to be a lot of issues on SO dealing with MapRoute problems. I've read through a bunch of them, but I can't see what I'm doing wrong in my implementation. I've got the following routes set up: routes.MapRoute( _ "FilesDisplay", _ "{controll

  • Why is ASP.NET MVC MapRoute popping up a Windows authentication dialog box? 2009-05-11

    This one has me stumped, and I think it might be a bug in Microsoft's MVC implementation. I am building a MVC website using VS2008 SP1. In an attempt to lockdown my website I edited my controller to look like this: 1 public class IdeaController : Con

  • Login control in MVC not displaying username after account creation redirect 2009-08-21

    I'm working with a custom membership provider in conjunction with the default Account controller that comes with the MVC example app. Everything is going smoothly except for one tiny thing: After a user creates an account and is autom

  • MVC membership - wrong username casing used 2010-07-22

    When a user logs in with the default implementation of the membership service in an mvc project, they are logged in with a username with whatever case they used when logging in. For example, if I create a user called John. If I then log in as

  • MVC MapRoute not routing with required parameter 2011-01-26

    I'm wanting the URL to my MVC application to be like: Which would in turn 'redirect' to Home/Details/Bob. I've set up the following MapRoute: routes.MapRoute( _ Nothing, _ "{personName}", _ New With {.controller = "Home", .action = "

  • .net mvc email as username returning error - InvalidProviderUserKey 2011-05-17

    I have a .Net MVC application that I am trying to use an email address as the username. I implemented the logic from this article where the username is masked as the email. However, when I try to call private readonly MembershipProvider _provider; Me

  • Why do Mvc Maproutes seem to break the DRY principle 2011-06-28

    I added the following route into my MVC app. routes.MapRoute("leads", "leads/{leadId}", new { controller = "Leads", action = "ViewLead" }); However, it seems that any action method off the leads controller now causes it to try to go to the ViewLead a

  • mvc -> Roles.IsUserInRole(username,role) 2010-07-23

    Do we need to add any references or import any namespace for Roles.IsUserInRole(username,role) - > is it not giving the right result. <% if(Model.Count < 1) {%> No User's Add Under You! <% } else { foreach (var item in Model) { %>

  • ASP.NET MVC - MapRoute and User Defined Paths 2011-03-19

    I have a problem with understanding ASP MVC3 directories system and map routing. For example: I want some controllers to put them into Admin directory, so way to user editing should look like: "http://localhost/Admin/Users/Edit/1", where admin - subd

  • Create a Asp MVC MapRoute that routes to partial named controllers 2011-11-28

    I want to create a MapRoute that will take the {controller} URL segment and treat it as a prefix to a controller name, something like the following… Context.MapRoute would be something like “AreaName/Widgets/{action}/{id}/{controller} Couple URL exam

  • how to map a Route like ( in MVC 3 2011-07-02

    I want to map a route like this: in ASP.NET MVC 3 application; How can I do it, please? Thanks to all, regards --------------Solutions------------- Maybe add custom route at the very beginning that would inherit from System.Web.Ro

  • MVC 3 wildcard route ie 2012-01-15

    I would like to create a simple route which will allow me to have ONLY one item listed after the base URL (other than when it's a controller), and for that item to be passed into a controller as a parameter. for example:

  • mvc url routing 2009-08-25

    How do I map something like The problem is I think that the MVC routing looks for the controller to determine how it should handle the mapping request. I am pretty new to ASP.NET MVC. However, based on the tutorials so far, the r

  • Is it possible to pass route value to show the name of the user without the controller name in MVC 2010-03-17

    I want to get the url for my site as "" without the controller name in MVC architecture, such that when i click the name of the particular user i want to show details of the user with just the name of the user showing in url. ---

  • How to use personalized urls in mvc application 2010-05-26

    I am working on a website in which many users can create their account and have a personalized page. I wish to provide them a twitter like url to access their pages, for example or . I am using mvc 1.0

  • how to write a route which include the username 2011-08-19

    I am building an mvc website, after the user login he can access his profile section pages and currently these pages URL is like that , what I want is to make the URL like that How to write thi

  • MVC route, query parameters 2011-10-20

    Two simple mvc3 routes, username and a default catch all. routes.MapRoute( "Users", "{username}", new { controller = "User", action = "Index"} ); routes.MapRoute( "Default", "{*url}", new { controller = "Default", action = "Index" } ); How do you mak

Copyright (C), All Rights Reserved.

processed in 0.113 (s). 11 q(s)