本文整理汇总了C#中User.AddToRole方法的典型用法代码示例。如果您正苦于以下问题:C# User.AddToRole方法的具体用法?C# User.AddToRole怎么用?C# User.AddToRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User.AddToRole方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddUserToRole
private static void AddUserToRole(User user, string role)
{
if (!(user.IsMember(role)))
{
user.AddToRole(role);
user.Alter();
}
}
示例2: AddUserToRoles
private static void AddUserToRoles(User user, params string[] roles)
{
if (roles.IsNullOrEmpty())
return;
foreach (var role in roles)
{
if (!(user.IsMember(role)))
{
user.AddToRole(role);
}
}
user.Alter();
}
示例3: BtnOk_Click
public void BtnOk_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string UserName = DropUserlist.SelectedItem.Text;
currentUser = new User(UserName);
foreach (ListItem item in chkboxRolelist.Items)
{
if (item.Selected == true)
{
currentUser.AddToRole(Convert.ToInt32(item.Value));
}
else
{
currentUser.RemoveRole(Convert.ToInt32(item.Value));
}
}
lblTip.Text = "����ɹ���";
}
示例4: button1_Click
//add db
private void button1_Click(object sender, EventArgs e)
{
var dbName = textBoxDB.Text;
string userName = textBoxUser.Text;
var serverName = "."; // SQL Server Instance name
Server svr = new Server(serverName);
var db = new Database(svr, dbName);
db.Create();
if (db != null)
{
// In case I need to add a login to sql
//Login login = new Login(svr, "beacon");
//login.DefaultDatabase = "master"; // Logins typically have master as default database
//login.LoginType = LoginType.SqlLogin;
//login.Create("foobar", LoginCreateOptions.None); // Enter a suitable password
//login.Enable();
if(userName != "")
{
User user = new User(db, userName);
user.UserType = UserType.SqlLogin;
user.Login = userName;
user.Create();
List<object> listOfPermissions = checkedListBoxPermissions.CheckedItems.OfType<object>().ToList();
foreach(var p in listOfPermissions)
{
user.AddToRole(p.ToString());
}
}
}
comboBoxDatabases.Items.Clear();
populateDatabases();
}
示例5: EnableDatabaseRoleForLogin
/// <summary>
/// Enables the database role for login.
/// </summary>
/// <param name="connectionString">The connection string.</param>
/// <param name="loginUsername">The login username.</param>
/// <param name="role">The role.</param>
public static void EnableDatabaseRoleForLogin(string connectionString, string loginUsername, string role)
{
EnableServerLoginForWindowsUser(connectionString, loginUsername);
var builder = new SqlConnectionStringBuilder(connectionString);
var server = new Server(builder.DataSource);
var database = new Database(server, builder.InitialCatalog);
var user = new User(database, loginUsername);
if (database.Users.Contains(loginUsername))
{
user.Login = loginUsername;
user.Create();
}
user.AddToRole(role);
}
示例6: Main
//.........这里部分代码省略.........
df1.FileName = databaseFileName;
df1.Size = 10.0*1024.0;
df1.GrowthType = FileGrowthType.Percent;
df1.Growth = 25.0;
try
{
newDB.Create();
}
catch (Exception e)
{
WriteLine(string.Format("Could not create database \"{0}\"", newDatabase), OutputKind.Error);
ReportException(e);
WarnAndExit("");
}
}
//copy the users
foreach (User oldUser in db.Users)
{
User newUser = newDB.Users[oldUser.Name];
if (newUser == null)
{
Notify("Processing user " + oldUser.Name);
try
{
newUser = new User(newDB, oldUser.Name);
newUser.DefaultSchema = oldUser.DefaultSchema;
newUser.UserType = oldUser.UserType;
newUser.Login = oldUser.Login;
newDB.Users.Add(newUser);
newUser.Create();
StringCollection roles = oldUser.EnumRoles();
foreach (string role in roles) newUser.AddToRole(role);
newUser.Alter();
}
catch (Exception e)
{
ReportException(e);
}
}
}
//copy schemas
foreach (Schema oldSchema in db.Schemas)
{
Schema newSchema = newDB.Schemas[oldSchema.Name];
if (newSchema == null)
{
Notify("Processing schema " + oldSchema.Name);
try
{
newSchema = new Schema(newDB, oldSchema.Name);
newSchema.Owner = oldSchema.Owner;
newDB.Schemas.Add(newSchema);
newSchema.Create();
}
catch (Exception e)
{
ReportException(e);
}
}
}
//copy datatype
foreach (UserDefinedDataType oldType in db.UserDefinedDataTypes)
示例7: CreateLogin
/// <summary>
/// Creates a database login for the specified user.
/// </summary>
/// <param name="userName">Name of the user.</param>
/// <param name="password">The password for the user.</param>
/// <param name="makeDatabaseOwner">If set to <c>true</c>, the user will be a database owner (db_owner).</param>
public void CreateLogin(string userName, string password, bool makeDatabaseOwner)
{
if (!String.IsNullOrWhiteSpace(userName))
{
Login login = new Login(SqlServer, userName);
login.DefaultDatabase = _info.DatabaseName;
login.LoginType = LoginType.SqlLogin;
login.PasswordPolicyEnforced = false;
login.PasswordExpirationEnabled = false;
login.Create(password, LoginCreateOptions.None);
// Create new user and map to login account
User user = new User(SqlServer.Databases[_info.DatabaseName], userName);
user.Login = userName;
user.Create();
if (makeDatabaseOwner)
{
user.AddToRole("db_owner");
}
}
}
示例8: TryCreate
private void TryCreate(Database database, SqlServerUser user)
{
try
{
Logger.WriteLine("User: {0}", user);
var newUser = new User(database, user.Name)
{
Login = user.Login
};
newUser.Create();
foreach (var role in user.Roles)
{
newUser.AddToRole(role);
}
}
catch (FailedOperationException ex)
{
Logger.WriteLine("Adding user {0} failed. Reason: {1} ", user.Name, ex.Message);
}
}
示例9: CreateUser
public void CreateUser(string name, string database, string defaultSchema, string login, string[] roles)
{
Database db = _server.Databases[database];
User user = new User(db, name) {Login = login, DefaultSchema = defaultSchema};
user.Create();
for (int i = 0; i < roles.Length; i++)
user.AddToRole(roles[i]);
user.Alter();
}