日期:2015-03-14 浏览次数:5687 次
|zyciis| IIS创建网站和应用程序池后,如何设置他为主目录的执行权限为“纯脚本”还有他的“应用程序名”
创建应用程序池和创建网站代码如下
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();
完整的测试代码
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.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG .asmx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG .aspx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG .axd,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG .vsdisco,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG .rem,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG .soap,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG .config,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .cs,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .csproj,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .vb,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .vbproj,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .webinfo,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .licx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .resx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .resources,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .xoml,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG .rules,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG .master,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .skin,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .compiled,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .browser,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .mdb,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .jsl,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .vjsproj,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .sitemap,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .msgx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG .ad,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .dd,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .ldd,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .sd,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .cd,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .adprototype,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .lddprototype,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .sdm,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .sdmDocument,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .ldb,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .svc,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG .mdf,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .ldf,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .java,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .exclude,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG .refresh,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG"; String[] ScriptMapsList = System.Text.RegularExpressions.Regex.Split(ScriptMaps, "\r\n"); ///注意:这里没有进行进行端口存在的检查 // Access Flags const int MD_ACCESS_READ = 0x00000001; //Allow read access. const int MD_ACCESS_SCRIPT = 0x00000200; // Allow script execution. 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] = "测试网站"; 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();