J
Jonathan Wood
I've spent days trying to come up with a solution. I'd appreciate it if
anyone can help.
My site requires all users to log on. There are three different roles of
users, and each user type will have access to a completely different set of
pages. "Client" pages are in the root folder and "Admin" and "Trainer" pages
each have their own subfolders.
The problem is that when a user goes to the domain, I want to redirect
"Admin" and "Trainer" users to the appropriate subfolder.
I tried to redirect users in response to the LoggedIn event handler for the
Login control (even though the Roles object has not been initialized then).
That works but if the user clicks the "remember me" box, they can come back
to the site, still logged in, without firing this event.
So I tried to put code in /Default.aspx to test for "Admin" or "Trainer"
users but, since these users don't have access to /Default.aspx, that code
never runs for these users.
So then I tried something like the following:
protected void Application_PostAcquireRequestState(object sender, EventArgs
e)
{
string url = HttpContext.Current.Request.RawUrl;
if (url.EndsWith("Default.aspx", StringComparison.OrdinalIgnoreCase))
{
switch (Users.GetRole())
{
case Users.UserRoles.RoleAdmin:
HttpContext.Current.Server.Transfer("~/Admin/Default.aspx");
break;
case Users.UserRoles.RoleTrainer:
HttpContext.Current.Server.Transfer("~/Trainer/Default.aspx");
break;
}
}
}
Note: Users.GetRole is a custom routine and works when called.
This approach is just plain messy. It's hard to determine exactly when the
user is actually being taken to the default page. If they haven't logged on,
ASP.NET will be redirecting the user to my login page. Then, when I click
"logout," it prevents the page being redirected to the login page. I just
can't seem to make this work reliably.
Any suggestions?
Thanks.
anyone can help.
My site requires all users to log on. There are three different roles of
users, and each user type will have access to a completely different set of
pages. "Client" pages are in the root folder and "Admin" and "Trainer" pages
each have their own subfolders.
The problem is that when a user goes to the domain, I want to redirect
"Admin" and "Trainer" users to the appropriate subfolder.
I tried to redirect users in response to the LoggedIn event handler for the
Login control (even though the Roles object has not been initialized then).
That works but if the user clicks the "remember me" box, they can come back
to the site, still logged in, without firing this event.
So I tried to put code in /Default.aspx to test for "Admin" or "Trainer"
users but, since these users don't have access to /Default.aspx, that code
never runs for these users.
So then I tried something like the following:
protected void Application_PostAcquireRequestState(object sender, EventArgs
e)
{
string url = HttpContext.Current.Request.RawUrl;
if (url.EndsWith("Default.aspx", StringComparison.OrdinalIgnoreCase))
{
switch (Users.GetRole())
{
case Users.UserRoles.RoleAdmin:
HttpContext.Current.Server.Transfer("~/Admin/Default.aspx");
break;
case Users.UserRoles.RoleTrainer:
HttpContext.Current.Server.Transfer("~/Trainer/Default.aspx");
break;
}
}
}
Note: Users.GetRole is a custom routine and works when called.
This approach is just plain messy. It's hard to determine exactly when the
user is actually being taken to the default page. If they haven't logged on,
ASP.NET will be redirecting the user to my login page. Then, when I click
"logout," it prevents the page being redirected to the login page. I just
can't seem to make this work reliably.
Any suggestions?
Thanks.