[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

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");
            }
        }
    }
0
pointeman
Asked:
pointeman
  • 3
  • 2
1 Solution
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now