Default Role on registeration

Topics: Business Logic Layer
Jun 16, 2010 at 11:50 AM

As soon as user regsiter i want default role to be Editors.

How do i do that?

I tried doing this on Account/Register.aspx page

but it doesn't seem to be working.

Roles.AddUserToRole(RegisterUser.UserName, "Editors");

Jun 16, 2010 at 12:44 PM

Are you adding your code in the right place? The following works.

protected void RegisterUser_CreatedUser(object sender, EventArgs e)
    {
        Roles.AddUserToRole(RegisterUser.UserName, "Editors");
        FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);

        string continueUrl = RegisterUser.ContinueDestinationPageUrl;
        if (String.IsNullOrEmpty(continueUrl))
        {
            continueUrl = "~/";
        }
        Response.Redirect(continueUrl);
    }
}
Jun 16, 2010 at 2:09 PM

It's working now. I was adding it at wrong place. Thank you.