日期:2014-05-18  浏览次数:20462 次

|zyciis| IIS创建网站和应用程序池后,如何设置他为主目录的执行权限为“纯脚本”还有他的“应用程序名”
创建应用程序池和创建网站代码如下
C# code

String appPoolName = "MyApp2";
DirectoryEntry newpool;
DirectoryEntry apppools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
newpool = apppools.Children.Add(appPoolName,"IIsApplicationPool");
newpool.Properties["AppPoolIdentityType"][0] = "2";
newpool.Properties["IdleTimeout"][0] = 0;
newpool.Properties["MaxProcesses"][0] = 5;

newpool.CommitChanges();
//创建网站
DirectoryEntry Service = new DirectoryEntry("IIS://localhost/W3SVC");
DirectoryEntry Server;
int i = 0;
IEnumerator ie = Service.Children.GetEnumerator();

while (ie.MoveNext())
{
    Server = (DirectoryEntry)ie.Current;
    if (Server.SchemaClassName == "IIsWebServer")
    {
        if (Convert.ToInt32(Server.Name) > i)
            i = Convert.ToInt32(Server.Name);
    }
}

i++;

Server = Service.Children.Add(i.ToString(), "IIsWebServer");
Server.Properties["ServerBindings"].Value = ":8551:";
Server.Properties["ServerComment"][0] = "测试网站";
DirectoryEntry root = Server.Children.Add("Root", "IIsWebVirtualDir");
root.Properties["path"][0] = @"C:\b\xx";


Service.CommitChanges();
Server.CommitChanges();
root.CommitChanges();
//这里应该就是添加应用程序池的。。不知道这里不么改
object[] param = { 0, appPoolName, true };
root.Invoke("AppCreate3", param);
Server.Invoke("start", new object[0]);


然后现在已经能够设置网站的应用程序池为:“MyApp2”
但现问题为:
1:但是他的“执行权限”为“无”!如何设置为“纯脚本”
2:他的“应用程序名”如何设置?我给添加
  Server.Properties["AppFriendlyName"][0] = "我的测试网站";
  没有用
3:在我的应用程序池下面的“MyApp2”显示当前这个网站的描述为“Root”怎么改显示为“我的测试网站”,也就是我那个网站的“应用程序名”相同

谢谢

------解决方案--------------------
Server = Service.Children.Add(i.ToString(), "IIsWebServer");
Server.Properties["ServerBindings"].Value = ":8551:";
Server.Properties["ServerComment"][0] = "测试网站";
Server.CommitChanges();
DirectoryEntry root = Server.Children.Add("Root", "IIsWebVirtualDir");
root.Properties["Path"][0] = @"C:\b\xx";
root.Properties["AccessFlags"][0] = MD_ACCESS_READ | MD_ACCESS_SCRIPT;
root.Properties["ScriptMaps"].Value = ScriptMapsList;
root.Properties["AspEnableParentPaths"][0] = true;
root.Properties["AppRoot"][0] = "LM/W3SVC/" + i + "/Root";
root.Invoke("AppCreate", true);
root.CommitChanges();
//注意:AppFriendlyName必须放在root.Invoke("AppCreate", true);root.CommitChanges();之后。
root.Properties["AppFriendlyName"][0] = "我的测试网站";
root.CommitChanges();
object[] param = { 0, appPoolName, true };
root.Invoke("AppCreate3", param);
Server.Invoke("start", new object[0]);
Service.CommitChanges();

完整的测试代码
C# code
string ScriptMaps = @".asp,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.cer,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.cdx,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.asa,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.idc,C:\WINDOWS\system32\inetsrv\httpodbc.dll,5,GET,POST
.shtm,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
.shtml,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
.stm,C:\WINDOWS\system32\inetsrv\ssinc.dll,5,GET,POST
.asax,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.ascx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.ashx,C:\WINDOWS\Microsoft.