gpt4 book ai didi

database - 如何在 webmatrix 中自动分配角色

转载 作者:搜寻专家 更新时间:2023-10-30 19:51:00 24 4
gpt4 key购买 nike

我想自动为新注册用户分配数据库中的成员角色。

最佳答案

WebMatrix 示例入门站点应用程序 - Account\Register.cshtml

测试成功。

// Check if user already exists
var user = db.QuerySingle("SELECT Email FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", email);
if (user == null) {
// Insert email into the profile table
db.Execute("INSERT INTO UserProfile (Email) VALUES (@0)", email);

//Roles have already been added to webpages_Roles table
//Logic to determine role for e-mail (user) being added for the first time
if (email == "John@gmail.com") {
var userName=email;
var roleName="Administrator";
Roles.AddUserToRole(userName, roleName);
}
else if (email == "Greg@gmail.com") {
var userName=email;
var roleName="Guest";
Roles.AddUserToRole(userName, roleName);
}
else {
//All others are assigned the role of Member
var username=email;
var roleName="Member";
Roles.AddUserToRole(userName, roleName);
}

关于database - 如何在 webmatrix 中自动分配角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23488794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com