如何在Account/Register.aspx.cs中添加角色 [英] How add role in Account/Register.aspx.cs

查看:166
本文介绍了如何在Account/Register.aspx.cs中添加角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:
我将asp.net登录控件拖动到页面上.并在配置工具期间创建了一些角色:网站"->页面配置"(例如,管理员,用户,开发人员).
下面我做了什么:
1.在register.aspx上添加一个下拉列表,并绑定到aspnet_Roles表. 2.当我注册一个新用户时,我想在表aspnet_UsersinRoles中添加一条记录.
3.因此,我将代码添加到下面的register.aspx.cs中:

Hi, guys:
I drag a asp.net 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;

        Response.Redirect(continueUrl);


其结果是:
1.将用户和角色插入表aspnet_UsersinRoles中.
问题是:
1.页面显示错误,输入用户名和密码始终是注销状态.
2.网址包含一些查询字符串" http://localhost:9633/HicCommunity/Account /Login.aspx?ReturnUrl=%2fHicCommunity%2fDefault.aspx [ ^ ]"

代码有问题吗?请举手.谢谢


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

推荐答案

确定,我知道原因,并且代码确定.

原因是我在访问规则"中将角色设置为拒绝

现在,我对其进行修改并可以使用.
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.


这篇关于如何在Account/Register.aspx.cs中添加角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆