我在创建系统用户的时候,提示"一般性拒绝访问错误";创建IIS里面的应用程序池的时候,会提示"拒绝访问",代码在下面贴出来,请高手指点
/// <summary>
/// 创建系统用户
/// </summary>
/// <param name="Username">用户名</param>
/// <param name="Userpassword">密码</param>
public void CreateUser(string Username, string Userpassword)
{
DirectoryEntry de = null;
try
{
de = new DirectoryEntry("WinNT://" + Environment.MachineName);
DirectoryEntry deSite = de.Children.Add(Username, "User");
deSite.Properties["FullName"].Add(Username);
deSite.Invoke("SetPassword", Userpassword);
//deSite.UsePropertyCache = true;
//deSite.Invoke("Put", "Description", " User from .NET for Site");
//deSite.Invoke("Put", "UserFlags", 66049);
//deSite.Invoke("Put", "HomeDirectory", "E:\\space\\");
deSite.CommitChanges();
DirectoryEntry grp = de.Children.Find("Users", "group");//Users组
if (grp.Name != "")
{
grp.Invoke("Add", deSite.Path.ToString());//将用户添加到某组
}
}
catch (Exception)
{ throw;
}
}/// <summary>
/// 创建应用程序池
/// </summary>
/// <param name="metabasePath">连接字符串[IIS://localhost/W3SVC/AppPools]</param>
/// <param name="appPoolName">程序池名称</param>
/// <param name="Username">用户名</param>
/// <param name="Password">密码</param>
static public bool CreateAppPool(string metabasePath, string appPoolName/*, string Username, string Password*/)
{
try
{
if (metabasePath.EndsWith("/W3SVC/AppPools"))
{
DirectoryEntry newpool;
DirectoryEntry apppools = new DirectoryEntry(metabasePath);
newpool = apppools.Children.Add(appPoolName, "IIsApplicationPool");
//newpool.Properties["WAMUserName"][0] = Username;
//newpool.Properties["WAMUserPass"][0] = Password;
//newpool.Properties["AppPoolIdentityType"][0] = "3";
newpool.Properties["AppPoolIdentityType"][0] = "1";
newpool.CommitChanges();
return true;
}
else
{
return false;
}
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// 创建系统用户
/// </summary>
/// <param name="Username">用户名</param>
/// <param name="Userpassword">密码</param>
public void CreateUser(string Username, string Userpassword)
{
DirectoryEntry de = null;
try
{
de = new DirectoryEntry("WinNT://" + Environment.MachineName);
DirectoryEntry deSite = de.Children.Add(Username, "User");
deSite.Properties["FullName"].Add(Username);
deSite.Invoke("SetPassword", Userpassword);
//deSite.UsePropertyCache = true;
//deSite.Invoke("Put", "Description", " User from .NET for Site");
//deSite.Invoke("Put", "UserFlags", 66049);
//deSite.Invoke("Put", "HomeDirectory", "E:\\space\\");
deSite.CommitChanges();
DirectoryEntry grp = de.Children.Find("Users", "group");//Users组
if (grp.Name != "")
{
grp.Invoke("Add", deSite.Path.ToString());//将用户添加到某组
}
}
catch (Exception)
{ throw;
}
}/// <summary>
/// 创建应用程序池
/// </summary>
/// <param name="metabasePath">连接字符串[IIS://localhost/W3SVC/AppPools]</param>
/// <param name="appPoolName">程序池名称</param>
/// <param name="Username">用户名</param>
/// <param name="Password">密码</param>
static public bool CreateAppPool(string metabasePath, string appPoolName/*, string Username, string Password*/)
{
try
{
if (metabasePath.EndsWith("/W3SVC/AppPools"))
{
DirectoryEntry newpool;
DirectoryEntry apppools = new DirectoryEntry(metabasePath);
newpool = apppools.Children.Add(appPoolName, "IIsApplicationPool");
//newpool.Properties["WAMUserName"][0] = Username;
//newpool.Properties["WAMUserPass"][0] = Password;
//newpool.Properties["AppPoolIdentityType"][0] = "3";
newpool.Properties["AppPoolIdentityType"][0] = "1";
newpool.CommitChanges();
return true;
}
else
{
return false;
}
}
catch (Exception)
{
return false;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货