ASP.NET C# 将用户添加到角色
大家好,我有一个包含 UserID 和其他属性的详细信息视图。我希望单击按钮能够更新角色租用者显示的用户 ID。因此,我使用 CommandName SetToRenter 设置一个按钮,并在 C# 中包含以下代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
public partial class adminonly_approval : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
void DetailsView1_ItemCommand(Object sender, DetailsViewCommandEventArgs e){
if (e.CommandName == "SetToRenter")
{
DetailsViewRow row = DetailsView1.Rows[0];
String UserID = row.Cells[0].Text;
MembershipUser memUser = Membership.GetUser(UserID);
Roles.AddUserToRole(memUser.UserName, "renter");
}
}
}
单击该按钮时,它只会刷新代码,并且无法将角色设置为租户。
有什么想法吗?
Hi All I a Details View containing UserID and other attributes. I want on button click to be able to update the UserID shown with the Role Renter. I therefore set a button with the CommandName SetToRenter and have the following code in the C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
public partial class adminonly_approval : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
void DetailsView1_ItemCommand(Object sender, DetailsViewCommandEventArgs e){
if (e.CommandName == "SetToRenter")
{
DetailsViewRow row = DetailsView1.Rows[0];
String UserID = row.Cells[0].Text;
MembershipUser memUser = Membership.GetUser(UserID);
Roles.AddUserToRole(memUser.UserName, "renter");
}
}
}
On click of the button it just refreshes the code and is failing to set the role to renter.
Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当你调试代码时,你是否进入了 ItemCommand 方法,如果你这样做了,也许你检查数据库时,“renter”角色已被添加到 memUser 的 asp.net 角色表中,但没有显示更改由于某些不明原因的详细信息视图。
Do you get into the ItemCommand method when you debug your code, if you do, thne perhaps if you check the database, the "renter" role had been added to the asp.net roles table for memUser but does not show the change on the DetailsView for some obscure reason.