S
Steve Commisso
I'm trying to create a forked login where users of certain roles will be
redirected to specific pages.
The easy way to do this would be to do the redirecting in the
Page_Load() of the default page after login, but I'd like to skip this
step and just have the Login control go ahead and do it.
So my plan is this: override the OnLoggedIn() method of the Login
control with my own custom method that changes the DestinationPageUrl
property of the Login control.
Here's the code (in my code-behind page, Login.aspx.cs):
void OnLoggedIn(object sender, EventArgs e)
{
if (System.Web.Security.Roles.IsUserInRole ("engineers"))
Login1.DestinationPageUrl = "Engineering.aspx";
else
Login1.DestinationPageUrl = "Default.aspx";
}
Here's the ASP code for the control (Login.aspx):
<asp:Login ID="Login1" Runat="server"
OnLoggedIn=OnLoggedIn
</asp:Login>
I'm running into a few problems:
1) I know my method is overloading properly because whatever I put for
the Url under the 'else' statement is where I'm redirected to. This
means that the IsUserInRole() method is always returning false -- but
isn't the OnLoggedIn() method supposed to fire right after the user is
validated? Because of this, shouldn't the IsUserInRole() method work
since there's a current user to check?
2) If I'm redirected to the Login page so that there's a ReturnURL="..."
in the address bar, that ReturnURL seems to override the
DestinationPageURL property, which I thought I had read overrides all
default redirections. I guess this is wrong?
So basically, is it feasible to do this 'forking' via the Login control?
Or am I going to have to do it somewhere else.
Thanks in advance,
Steve Commisso
redirected to specific pages.
The easy way to do this would be to do the redirecting in the
Page_Load() of the default page after login, but I'd like to skip this
step and just have the Login control go ahead and do it.
So my plan is this: override the OnLoggedIn() method of the Login
control with my own custom method that changes the DestinationPageUrl
property of the Login control.
Here's the code (in my code-behind page, Login.aspx.cs):
void OnLoggedIn(object sender, EventArgs e)
{
if (System.Web.Security.Roles.IsUserInRole ("engineers"))
Login1.DestinationPageUrl = "Engineering.aspx";
else
Login1.DestinationPageUrl = "Default.aspx";
}
Here's the ASP code for the control (Login.aspx):
<asp:Login ID="Login1" Runat="server"
OnLoggedIn=OnLoggedIn
</asp:Login>
I'm running into a few problems:
1) I know my method is overloading properly because whatever I put for
the Url under the 'else' statement is where I'm redirected to. This
means that the IsUserInRole() method is always returning false -- but
isn't the OnLoggedIn() method supposed to fire right after the user is
validated? Because of this, shouldn't the IsUserInRole() method work
since there's a current user to check?
2) If I'm redirected to the Login page so that there's a ReturnURL="..."
in the address bar, that ReturnURL seems to override the
DestinationPageURL property, which I thought I had read overrides all
default redirections. I guess this is wrong?
So basically, is it feasible to do this 'forking' via the Login control?
Or am I going to have to do it somewhere else.
Thanks in advance,
Steve Commisso