Click here to Skip to main content
15,794,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, guys:
I drag a login control on the page.And also create some roles during config tool: "website"-->"page configuration"(roles e.g. admin, user, developer).
What I did belows:
1. add a drop down list on the register.aspx, and binding to the aspnet_Roles table.
2. when I register a new user, I want to add one record in the table aspnet_UsersinRoles.
3. so i add the codes on the register.aspx.cs below:
using (ASPNETDBModel.ASPNETDBEntities accountEntities = new ASPNETDBModel.ASPNETDBEntities())
            rolename = from role in accountEntities.aspnet_Roles
                              where role.RoleId == new Guid(ddList.SelectedValue)
                              select role.RoleName;

            Roles.AddUserToRole(RegisterUser.UserName, rolename.First());
        FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);

        string continueUrl = RegisterUser.ContinueDestinationPageUrl;


The result is :
1. the user and role in inserted in the table aspnet_UsersinRoles.
The problem is :
1. The page is rendered wrongly, it is alwayse unlogon state event I input the use name and password.
2. the url contains some querystring "http://localhost:9633/HicCommunity/Account/Login.aspx?ReturnUrl=%2fHicCommunity%2fDefault.aspx[^]"

Any problem in codes? Please give your hands. Thanks

1 solution

ok, I know the reason, and the code is ok.

the reason is I set the role deny in "Access Rules"

Now I modify it and works.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900