I was wondering if there was anyway to navigate different types of user's to their corrowsponding areas once they have successfully entered their login details and clicked login.
I know this can be done using buttons with the following code within their Button_Click sub...
If User.IsInRole("Admin") Then Response.Redirect("~/Admin/admin.aspx")
Else
Response.Redirect("~/Errorpage.aspx")
End If
However im not sure how to indentify the Login button from the login form and if doing so will interfere with the login process.
<asp:LoginView runat="server">
<AnonymousTemplate>
You're not logged in
</AnonymousTemplate>
<LoggedInTemplate>
You're logged in
</LoggedInTemplate>
</asp:LoginView>
<asp:LoginView runat="server">
<RoleGroups>
<asp:RoleGroup Roles="Admin, Manager">
<ContentTemplate>
You're in an important role
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
How could I use this to navigate the user and the admin to different locations (.aspx pages in separate folders) once they have entered their username/password and selected login via a basic login form?
I'm sorry -- I misunderstood your original question.
The Login control has a LoggedIn event you could handle. The Login control also has a UserName property to see who the user is and a DestinationPageUrl than you can set to indicate where the page should redirect.
These are just events so you would handle these like any other events in WebForms. I don't have a formal example offhand of these specific events, but here's the quick sample I did:
The problem you're going to run into is that the user isn't yet really logged into the current request (this is the request where the user submits username/password) so the User.IsInRole() won't work until the next request into the app. You could always
use the Login control's UserName property to lookup their roles and then build your logic on that.
Yeah I understand what you mean as the user hasn’t actually been logged in yet the Role property wouldn’t be of any use.
I think I need to learn more about what property’s I can place within the tags of each type of asp tool and then go from there trying to handle them. Is the correct wording for parts such as ‘onloggedin="_login_LoggedIn"’ an attribute or a property?
I think I need to learn more about what property’s I can place within the tags of each type of asp tool and then go from there trying to handle them. Is the correct wording for parts such as ‘onloggedin="_login_LoggedIn"’ an attribute or a property?
That syntax is a declarative event registration. There are other attributes you can set in there which are ultimately assigning properties to the control.
MichaelJD
0 Points
9 Posts
Create various DestinationPageUrl's for a login tool depending on a users roll.
Apr 26, 2012 09:57 PM|LINK
Hi guys.
I have a standard login field...
I was wondering if there was anyway to navigate different types of user's to their corrowsponding areas once they have successfully entered their login details and clicked login.
I know this can be done using buttons with the following code within their Button_Click sub...
If User.IsInRole("Admin") Then Response.Redirect("~/Admin/admin.aspx") Else Response.Redirect("~/Errorpage.aspx") End IfHowever im not sure how to indentify the Login button from the login form and if doing so will interfere with the login process.
Many Thanks.
DestinationPageURL if login Redirect
BrockAllen
All-Star
27524 Points
4902 Posts
MVP
Re: Create various DestinationPageUrl's for a login tool depending on a users roll.
Apr 26, 2012 10:51 PM|LINK
There is the LoginView control:
<asp:LoginView runat="server"> <AnonymousTemplate> You're not logged in </AnonymousTemplate> <LoggedInTemplate> You're logged in </LoggedInTemplate> </asp:LoginView> <asp:LoginView runat="server"> <RoleGroups> <asp:RoleGroup Roles="Admin, Manager"> <ContentTemplate> You're in an important role </ContentTemplate> </asp:RoleGroup> </RoleGroups> </asp:LoginView>DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
MichaelJD
0 Points
9 Posts
Re: Create various DestinationPageUrl's for a login tool depending on a users roll.
Apr 27, 2012 12:00 AM|LINK
How could I use this to navigate the user and the admin to different locations (.aspx pages in separate folders) once they have entered their username/password and selected login via a basic login form?
Thanks
BrockAllen
All-Star
27524 Points
4902 Posts
MVP
Re: Create various DestinationPageUrl's for a login tool depending on a users roll.
Apr 27, 2012 12:08 AM|LINK
I'm sorry -- I misunderstood your original question.
The Login control has a LoggedIn event you could handle. The Login control also has a UserName property to see who the user is and a DestinationPageUrl than you can set to indicate where the page should redirect.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
MichaelJD
0 Points
9 Posts
Re: Create various DestinationPageUrl's for a login tool depending on a users roll.
Apr 27, 2012 12:22 AM|LINK
It's fine :) I'm grateful for any help i can get.
Do you know where I could find code examples of those events being handled? Or could I use the 'If User.IsInRole' property I listed above.
Thanks
BrockAllen
All-Star
27524 Points
4902 Posts
MVP
Re: Create various DestinationPageUrl's for a login tool depending on a users roll.
Apr 27, 2012 12:37 AM|LINK
These are just events so you would handle these like any other events in WebForms. I don't have a formal example offhand of these specific events, but here's the quick sample I did:
ASPX: <asp:Login runat="server" ID="_login" onloggedin="_login_LoggedIn"></asp:Login> Codebehind: protected void _login_LoggedIn(object sender, EventArgs e) { if (_login.UserName == "brock") { _login.DestinationPageUrl = "~/admin.aspx"; } else { _login.DestinationPageUrl = "~/home.aspx"; } }The problem you're going to run into is that the user isn't yet really logged into the current request (this is the request where the user submits username/password) so the User.IsInRole() won't work until the next request into the app. You could always use the Login control's UserName property to lookup their roles and then build your logic on that.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
MichaelJD
0 Points
9 Posts
Re: Create various DestinationPageUrl's for a login tool depending on a users roll.
Apr 27, 2012 01:32 AM|LINK
That worked exactly as I wanted it to!
Yeah I understand what you mean as the user hasn’t actually been logged in yet the Role property wouldn’t be of any use.
I think I need to learn more about what property’s I can place within the tags of each type of asp tool and then go from there trying to handle them. Is the correct wording for parts such as ‘onloggedin="_login_LoggedIn"’ an attribute or a property?
Thanks a lot for your assistance.
BrockAllen
All-Star
27524 Points
4902 Posts
MVP
Re: Create various DestinationPageUrl's for a login tool depending on a users roll.
Apr 27, 2012 01:53 AM|LINK
That syntax is a declarative event registration. There are other attributes you can set in there which are ultimately assigning properties to the control.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/