代码如下:
private void CreateSiteIIS()
{
DataTable sdt;
sdt = db.GetDataTable(GetConnString(), "select SiteName,IPAddress,Port from sg_site where sitecode="+id);
if (sdt.Rows.Count > 0)
{
string h_path=Request.ServerVariables["APPL_PHYSICAL_PATH"].ToString();
string[] h_patharr = h_path.Split('\\');
string h_sname = sdt.Rows[0]["sitename"].ToString().Trim().Replace(" ", "_");
string h_ipadd = sdt.Rows[0]["IPAddress"].ToString().Trim();
string h_port = sdt.Rows[0]["Port"].ToString().Trim();
string h_machinename = "localhost";
DirectoryEntry Service = new DirectoryEntry("IIS://"+h_machinename+"/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++;
try
{
Server = Service.Children.Add(i.ToString(), "IIsWebServer");
Server.Properties["ServerComment"][0] = h_sname;
Server.Properties["Serverbindings"].Add(":" + h_port+ ":");
Server.Properties["AccessExecute"][0] = true;
Server.Properties["AccessScript"][0] = true;
Server.Properties["AccessRead"][0] = true;
Server.Properties["EnableDirBrowsing"][0] = false;
Server.Properties["DefaultDoc"][0] = "default.aspx";
Server.Properties["EnableDefaultDoc"][0] = true;
Server.Properties["AspAllowSessionState"][0] = true;
Server.Properties["AzEnable"][0] = true;
Server.Properties["AzImpersonationLevel"][0] = "0";
Server.Properties["AppIsolated"][0] = "2";
Server.Properties["AppPackageName"][0] = "测试应用程序名";
DirectoryEntry root = Server.Children.Add("Root", "IIsWebVirtualDir");
root.Properties["Path"][0] = @"E:\"+h_sname;
Service.CommitChanges();
Server.CommitChanges();
root.CommitChanges();
root.Invoke("AppCreate",true);
root.Invoke("AppCreate2", new object[1] { 2 });
Server.Invoke("start",new object[0]);
}
catch (Exception es)
{
throw (es);
}
}
}
配置信息可以正确的创建并添加 但惟独主目录下的“应用程序名”属性为空 奇怪的是他是开启状态 可以删除 但就是显示空
请各位朋友帮我看看这可能是什么问题造成的 谢谢