Redirecting a user after a user is logged in?

I am using the Login control to login a user. But I have the IsAuthenticated property of Identity object as false even after user has logged in, in Login_LoggedIn event. Also, I cannot get roles for the user in this event using Roles.GetRolesForUser.

Can someone tell me how I could redirect a user based on user's role (only one role is there in my app per user) when using Login control?

5/10/2007 3:28:10 AM 27051 articles. 1 followers. Follow

9 Replies

Similar Articles

[PageSpeed] 24
Get it on Google Play
Get it on Apple App Store

Have a look into this link

Hope this will help you

Ashok Raja

Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved.
5/10/2007 5:02:25 AM

But I have the IsAuthenticated property of Identity object as false even after user has logged in, in Login_LoggedIn event. Also, I cannot get roles for the user in this event using Roles.GetRolesForUser.

Hi sun21170

You mean Login control doesn't work on your web application?

Best Regards
XiaoYong Dai
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
5/11/2007 9:24:48 AM
It does, but what I mentioned in my first post under this thread, does not work. May be that's how the Login control is designed to function as. But it does cause problems for the developer in redirecting users based on user roles. The only option I have is to go to database and get the logged in user's roles, which is not a good idea since it involves another trip to database.
5/12/2007 6:33:18 PM

If Roles.IsUserInRole(Login1.UserName, "WhateverRole")
    Response.Redirect("ThisPage.aspx, True)
ElseIf Roles.IsUserInRole(Login1.UserName, "SomeOtherRole")
    Response.Redirect("ThatPage.aspx, True)
ElseIf Roles.IsUserInRole(Login1.UserName, "YetAnotherRole")
    Response.Redirect("SomePage.aspx, True)

5/12/2007 9:46:45 PM

As usual, I made a mistake in my code LOL and can't edit the original post so here's the edit:

Put this in your Logged_In event:

If Roles.IsUserInRole(Login1.UserName, "WhateverRole")
    Response.Redirect("ThisPage.aspx", True)
ElseIf Roles.IsUserInRole(Login1.UserName, "SomeOtherRole")
    Response.Redirect("ThatPage.aspx", True)
ElseIf Roles.IsUserInRole(Login1.UserName, "YetAnotherRole")
    Response.Redirect("SomePage.aspx", True)
End If

5/12/2007 10:16:46 PM

Roles.GetRolesForUser(myUser) returns a string array

To get the user's role with "Roles.GetRolesForUser(myUser)", you have to pick a string out of the returned string array.

5/12/2007 10:24:14 PM

Also, you may want to put this in your Login1 tag on the .aspx page that holds the login control


5/12/2007 10:31:21 PM

The answer to my question is as below:

  • Set the DestinationPageUrl  of the Login control to a page without any visible UI, so its just a processing page. Let's say this destination page is Redirect.aspx
  • In the Page_Load event of Redirect.aspx insert the roles check code as below. The methods/properties for Roles and Context.User.Identity.IsAuthenticated  do not return null in Redirect.aspx, as they do in events of the Login control.


If Context.User.Identity.IsAuthenticated Then

   Dim primaryRole As String = Roles.GetRolesForUser()(0)

   If primaryRole = "Public" Then



  ElseIf primaryRole = "Vendor" Then



  ElseIf primaryRole = "VendorAdmin" Then



 ElseIf primaryRole = "SuperAdmin" Then



 ElseIf primaryRole = "Admin" Then



 End If

End If



5/13/2007 2:34:18 PM

Hey Hey, you got her working, that's great!

5/14/2007 1:34:48 AM

Similar Artilces:

Users logging in as the same user..
HI there.. I have a problem with ASE12.0 .. I have created 10 users on the database and granted everybody permissions and all.. However, it seems everybody, no matter who logs in, logs in as the same user.. For eg... I have user logins John, Alex, Alan, Steve......etc etc And i created a user group for all of them (eg developers..) However, when they log on to isql, anything that they do will be under John, no matter if it is logins John, Alex, Steve... or etc etc.. If i do a sp_who.. all the connections will be listed as John. If they create tables, all table created will ...

Login control authenticates user and redirects, but does not log user in
I am trying our the "SQLite 3.0 Membership and Role Provider for ASP.NET 2.0" found here: since I do not have access to a SQL server. However I have run into a problem where the login control authenticates the user, then redirects to the redirect page, but ASP.NET detects the user as not logged in. One weird thing I noticed is that on the redirect page there is a check: if(Page.User.Identity!=null) this.Label1.Text = "Welcome," + Page.User.Identity.Name + "!"; The label control displays "Welcome, !" meaning the login c...

Login Control logs user in, but User is not authenticated, but user really is!
I am using aspnetmembershipprovider.  Everything works fine.  I slap a login control on my login page and am able to login and get to my secure folder etc.  When I try and put some code in the LoggedIn method "User.Identity.IsAuthenticated" = false, yet if I blow through that, I am logged, authenicated etc.  The documentation says that the LoggedIn event is "after the user is authenticated".  Any Ideas what is up?Thanks,TPS------------------------------------------------------Note Collaboration for your next confernce call. I am...

Web page not detecting a logged in user/user not logging in
Hey guysAs it stands, I've created two web pages within my app. One is a login page which is simply a blank page with the login control dragged on top. Within this control I redirect to my second page which contains a set of asp:Panels that are supposed to hide/display depending on which user is browsing the page.I've read several tutorials and at the moment, I've installed memberships/roles using the aspnet_regsql application. I've also used the web administration tool to create an 'administrators' role and create a user which is assigned to that role. I've also ...

User object (System.Security.Principal.IPrincipal) in my web service does not reflect currently logged on user.
I am using Forms authentication, 3.5 framework. I am calling a web method from a web form page; here is my problem: For some reason the User object (System.Security.Principal.IPrincipal) in my web service does not reflect currently logged on user. I know I am logged in correctly when I call the web service method (which I call using BeginX...X()). The weird thing is, I have other services whos methods DO reflect the currently logged in user (although these are called using AutoComplete extender, don't know why one works and the other does not).Please help  http://www.geneangelo...

Logging in a user onto one site logs out a user on another!
I am building a CMS application. All is on one computer during development using Visual Web Developer 2008 Express Edition and Windows XP Professional. Simply, I have one set of pages and each website's domain name points to the same pages, which load different data from the database, depending on the domain name. I am using the membership and roles framework but have left the applicationName blank in the roleManager and membership providers so that, as authenticated users create an account, a different applicationID is created for each domain name.  This way, the users and roles ...

User first log and another logs. Stats for users, etc.
Hello!I will write what I have. I have simple membership provider and login/register control. But when the new user come to site, he can sign up. After click "Finish" or "Register" button, his account is saving, but is inactivate. He also gets an email with link to active the account ( link is like:, where XXXXXX is simply his GUID number, so activating user is very easy - aproove user where userId = GUID). Ok. But I have problem. How to make simply logger counter for each user ?Simply: "Hello User, this is your 123 log on this portal" My q...

User resets password (email is sent with new password) user logs in with new password how to redirect to change password page?
I have a page with the login control, another page with a reset password control and another page with a change password control. Login and reset work perfectly. However what I want is very simple. Once the user recieves the email with their new generic password I would like the next time that user logins in (using the new generic password) to automatically take them to the change password page. I am sure there is an easy way to do this and I just haven't figured it out. I am using VS2008. Thank you for your help! Shawn The simplest way would be to update the aspnet_Membership t...

All users are logged off when one user loggs off
I have an application developed with ASP.NET and VB.NET now i am facing a very big problem.That is when in application if anyone user does signout all users who have logged in are also signed out.This means that if 1000 users are logged in and one loggs off then all other 999 users are also logged off. This is a tedious problem and i need it to be solved as soon as possible.Please help me out as soon as possible if you have any kind of solutions.   Hi Could you post more details especially what is the solution in your code and what is your authentication setting in IIS?Best...

Do not want to log in user after user is created
Hi there, By default, the aspnet membership create user wizard automatically log in user once the account is created. What is the way to bypass that? The scenario is, a current logged in admin is creating a new account and I want the admin to stays logged in instead of the newly created user.  set property LoginCreatedUser="False" of CreatUserWizard/GuruBhai Thanks guru_sarkar. I totally missed that ...

how to get user data from a logged in user
I have the standard login controls from ASP.NET 2.0 on my site. Now i've added a id field from another table to the aspnet_users table as FK. Now i want to use this ID (if the user is logged in) to populate my datagrid. How can i get this ID?  Erik    Check below link Work With Membership API HCHaissam Abdul MalakMCAD.NET| Blog | Hi Please follow the link and raise the problem you've meet :) Good luckBest RegardsXiaoYong DaiMicrosoft Online Community SupportPlease remember to click “Mark as Answer” on the ...

Redirecting after user has logged in
Hi,I have a web application on which users can place orders to buy goods. When the user try to place the order I need to check if they are logged in. If they are not logged in I direct them to the login page.After they have logged in successfully what is the best way to redirect them back to the page they came from? i.e back to books.aspx, movies.aspx etc.thanks odubhgaill2: I need to check if they are logged in  odubhgaill2:After they have logged in successfully what is the best way to redirect them back to the page they came from You must use forms authentication. Both of the...

Redirecting once a user logs in
When a user logs into a site using the login control. Is there a way to pass their credentials to a different site or application without having to reauthenticate? Also, when I used a SQL provider, it added the users, for example with a guid-looking id such as {139EDED6-C23D-4A46-9768-B831A328D68A}. The roles table looks the same way. Is this normal? How can I add roles dynamically using this on the fly? Finally, how can we use roles to enable and disable certain controls?Jason N. GaylordASPInsider and Microsoft MVP >Is there a way to pass their credentials ...

Cannot open user default database. Login failed. Login failed for user 'DOMAIN\User'. (.Net SqlClient Data Provider)
Hi when i try and open a database in sql server management studio i get the error "Cannot open user default database. Login failed. Login failed for user 'DOMAIN\User'. (.Net SqlClient Data Provider)", what can i do to rectify this, i have googled around and still havent found no answers. Which authentication mode is your Sql Server configured - MixedMode, Windows Authentication or Sql Server Authentication? Please refer to and    Ple...

Web resources about - Redirecting a user after a user is logged in? -

Advertise - Redirecting - YouTube
Search Call us: 1-855-500-2756 Get started Overview Why it Works Success Stories Get Started Make Video Ads Resources This page has moved. Redirecting ...

Aboriginal funds need redirecting - report
Aboriginal funds need redirecting - report

Freedom of speech: Redirecting our society to a dangerous course
Freedom of speech: Redirecting our society to a dangerous course

Leaked Federal Government mental health report recommends redirecting $1 billion from acute hospital ...
A report commissioned by the Federal Government recommends redirecting money from acute hospital care to community-based mental health services. ...

Sona talked of redirecting voters to wrong polls, court hears in robocalls trial
Michael Sona was overheard talking about American-style campaign politics to redirect voters to the wrong polling stations in the 2011 federal ...

Unscrupulous website adverts again redirecting some users to App Store from Safari
... granting any kind of permission… In iOS 8 beta 2, Apple supposedly had remedied the issue: “Safari now blocks ads from automatically redirecting ...

Play Store May Be Redirecting Some Search Terms To The Predefined Categories
The user experience on Android is never standing still, which is no more evident than in the Play Store itself. It seems Google may be trying ...

Please wait — redirecting to new Business page...

Click here if you are not redirected

Redirecting Financial Flow To Asia Pacific Crucial For Region’s Sustainable Growth
... (UNEP) notes, the Asia Pacific region is home to over half of the world’s population, but much less than half its natural resources. Redirecting ...

Resources last updated: 12/23/2015 9:20:51 PM