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


C# UserPrincipal.Delete方法代码示例

本文整理汇总了C#中System.DirectoryServices.AccountManagement.UserPrincipal.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# UserPrincipal.Delete方法的具体用法?C# UserPrincipal.Delete怎么用?C# UserPrincipal.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.DirectoryServices.AccountManagement.UserPrincipal的用法示例。


在下文中一共展示了UserPrincipal.Delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: When_Creating_Home_Directory__Then_It_Should_Have_The_Appropriate_Rights

        public void When_Creating_Home_Directory__Then_It_Should_Have_The_Appropriate_Rights()
        {
            var username = string.Format("testUser{0}", DateTime.Now.Millisecond);
            var administration = new AdministrationService();
            var context = new PrincipalContext(ContextType.Machine);
            var user = new UserPrincipal(context)
                           {
                               Name = username,
                               UserCannotChangePassword = false,
                               PasswordNeverExpires = true,
                           };
            user.SetPassword("!Password123");
            user.Save();

            GroupPrincipal grp = GroupPrincipal.FindByIdentity(context, "IIS_IUSRS");
            if (grp != null)
            {
                grp.Members.Add(user);
                grp.Save();
            }

            Assert.IsNotNull(grp);
            string dir = Path.Combine(ConfigurationManager.AppSettings["HomeDirectory"], username);
            administration.MkDir(username, dir);

            bool exists = Directory.Exists(dir);
            Assert.IsTrue(exists);

            Directory.Delete(dir);
            user.Delete();
        }
开发者ID:bisand,项目名称:IISAdmin,代码行数:31,代码来源:FileSystemTests.cs

示例2: RemoveWindowsAccount

 public void RemoveWindowsAccount(UserPrincipal user)
 {
     try
     {
         user.Delete();
         BatchState.State = UserProcessState.WIN_DELETE_OK;
     }
     catch (Exception)
     {
         BatchState.State = UserProcessState.WIN_DELETE_ERROR;
         throw;
     }
 }
开发者ID:rohansen,项目名称:userhelper,代码行数:13,代码来源:UserManagement.cs

示例3: When_Creating_New_Site__It_Should_Be_Present_In_IIS

        public void When_Creating_New_Site__It_Should_Be_Present_In_IIS()
        {
            var username = string.Format("testUser{0}", DateTime.Now.Millisecond);
            const string password = "!Password123";

            var administration = new AdministrationService();
            var context = new PrincipalContext(ContextType.Machine);
            var user = new UserPrincipal(context) {
                Name = username,
                UserCannotChangePassword = false,
                PasswordNeverExpires = true,
            };
            user.SetPassword(password);
            user.Save();

            var grp = GroupPrincipal.FindByIdentity(context, "IIS_IUSRS");
            if (grp != null)
            {
                grp.Members.Add(user);
                grp.Save();
            }

            Assert.IsNotNull(grp);
            var dir = Path.Combine(ConfigurationManager.AppSettings["HomeDirectory"], username);

            var info = Directory.CreateDirectory(dir);
            var security = info.GetAccessControl();
            security.AddAccessRule(new FileSystemAccessRule(username,
                                                            FileSystemRights.Read |
                                                            FileSystemRights.Write |
                                                            FileSystemRights.Modify |
                                                            FileSystemRights.CreateDirectories |
                                                            FileSystemRights.CreateFiles |
                                                            FileSystemRights.ReadAndExecute,
                                                            InheritanceFlags.ContainerInherit |
                                                            InheritanceFlags.ObjectInherit,
                                                            PropagationFlags.None,
                                                            AccessControlType.Allow));
            info.SetAccessControl(security);

            var server = new IisServer();

            // In order to make this work, you will have to add an entry to your host file or dns...
            const string fqdn = "www.test.com";
            server.AddWebSite(username, password, fqdn, dir, "http", string.Format("*:80:{0}", fqdn));

            using (var serverManager = new ServerManager())
            {
                var site = serverManager.Sites.FirstOrDefault(x => x.Name == fqdn);
                Assert.IsNotNull(site);

                var app = site.Applications.FirstOrDefault();
                Assert.IsNotNull(app);

                var pool = serverManager.ApplicationPools.FirstOrDefault(x => x.Name == fqdn);
                Assert.IsNotNull(pool);

                // Cleaning up...
                app.Delete();
                site.Delete();
                pool.Delete();

                serverManager.CommitChanges();
            }

            // Cleaning up...
            Directory.Delete(dir, true);
            user.Delete();
        }
开发者ID:bisand,项目名称:IISAdmin,代码行数:69,代码来源:IisTests.cs

示例4: EliminarUsuario

 /// <summary>
 /// Elimina un usuario
 /// </summary>
 /// <param name="usuario">Usuario a eliminar</param>
 public void EliminarUsuario(UserPrincipal usuario)
 {
     usuario.Delete();
 }
开发者ID:alonsovb,项目名称:ad-manager,代码行数:8,代码来源:ADAdministrador.cs


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