Login1 WebControl Redirect by Role?


 I like the simple to use Login webcontrol included in VS 2005, but I feel my hands are tied at times. I would like to do more that just authenticate, but authorize and redirect according to Roles. Users redirect to default.aspx while Admins redirect to admins.aspx....

 Note: using Aspnet_regsql.exe installed database!

 I know the database works because I don't have problems if I simply Authenticate then Redirect.

 I've found this doesn't work either:

 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (e.Authenticated)
        {
            if (Roles.IsUserInRole(Login1.UserName, "Administrators"))
            {
                Response.Redirect("~/Admin/admins.aspx");
            }
        }
    }
pointemanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lotusnotesnewbieCommented:

Could you try this?
In your login control add OnLoggedIn="login_OnLoggedIn"
    protected void login_OnLoggedIn(object sender, EventArgs e)
    {
 if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
          {
             if (System.Web.HttpContext.Current.User.IsInRole("admin"))
                    {
Response.Redirect("admin.aspx");
                  }
                    else
                    {
Response.Redirect("client.aspx");
                }
       }
    }
0
pointemanAuthor Commented:
I tried your code and still receive the same 'Failure Text' error message:
"Your login attempt was not successful. Please try again."
I had to remove all login and authenticate events from the codebehind page to get the Login1 control to work properly again.
I don't know if the Login1 control is very friendly...
 
0
lotusnotesnewbieCommented:
It happens usually when, the Remember Me checkbox is checked. Could you uncheck it and try once.
0
pointemanAuthor Commented:
It's never been checked...
0
pointemanAuthor Commented:
Okay, got the answer:
protected void Login1_LoggedIn(object sender, EventArgs e)
    {
        if (Roles.IsUserInRole(Login1.UserName, "Administrators"))
        {
            this.Response.Redirect("~/admin/default.aspx");
        }
        else if (Roles.IsUserInRole(Login1.UserName, "Users"))
        {
            this.Response.Redirect("~/user/default.aspx");

        } //Use with Login1 control
       
    }
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.