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?

sun21170
0
sun21170
5/10/2007 3:28:10 AM
📁 asp.net.security
📃 27051 articles.
⭐ 1 followers.

💬 9 Replies
👁️‍🗨️ 936 Views



Have a look into this link
http://quickstart.developerfusion.co.uk/QuickStart/aspnet/doc/ctrlref/login/login.aspx
Hope this will help you

Ashok Raja
www.iGold.in

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.
0
AshokRaja
5/10/2007 5:02:25 AM

            
sun21170:

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.
0
XiaoYong
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.

sun21170
0
sun21170
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)
etc.
etc.
0
hypercode
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)
etc.
etc.
End If
0
hypercode
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.
0
hypercode
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
DestinationPageUrl
=""
0
hypercode
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
       Response.Redirect(

"~/Pub.aspx")


  ElseIf primaryRole = "Vendor" Then
     Response.Redirect(

"~/Vendor.aspx")


  ElseIf primaryRole = "VendorAdmin" Then
    Response.Redirect(

"~/VendorAdmin.aspx")


 ElseIf primaryRole = "SuperAdmin" Then
    Response.Redirect(

"~/SuperAdmin.aspx")


 ElseIf primaryRole = "Admin" Then
    Response.Redirect(

"~/Admin.aspx")


 End If


End If



 

sun21170
0
sun21170
5/13/2007 2:34:18 PM

Hey Hey, you got her working, that's great!
0
hypercode
5/14/2007 1:34:48 AM
Reply: