当前位置: 首页>>代码示例>>C#>>正文


C# User.AddToRole方法代码示例

本文整理汇总了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();
     }
 }
开发者ID:valhallasw,项目名称:csdb,代码行数:8,代码来源:DbPermissionsHelper.cs

示例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();
 }
开发者ID:valhallasw,项目名称:csdb,代码行数:13,代码来源:DbPermissionsHelper.cs

示例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 = "����ɹ���";
 }
开发者ID:sidny,项目名称:d4d-studio,代码行数:17,代码来源:UserAssignmentRole.aspx.cs

示例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();
        }
开发者ID:challsett,项目名称:coltrane,代码行数:38,代码来源:Form1.cs

示例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);
        }
开发者ID:PaulStovell,项目名称:bindable,代码行数:21,代码来源:SqlDatabaseHelper.cs

示例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)
开发者ID:Saleslogix,项目名称:SLXToolsContrib,代码行数:67,代码来源:Program.cs

示例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");
                }
            }
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:31,代码来源:DatabaseManipulator.cs

示例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);
     }
 }
开发者ID:pedershk,项目名称:dotnetprograms,代码行数:20,代码来源:RestoreTask.cs

示例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();
        }
开发者ID:Ashna,项目名称:ShayanDent,代码行数:12,代码来源:SqlServerManager.cs


注:本文中的User.AddToRole方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。