安装包中,属性的配置问题
请问大虾,我要配置IIS 的网站中的 "应用程序名" 和 选中目录安全性下面的"集成Windows 身份验证"。先有代码如下:
public void CreateWebSite(string serverID, string serverComment, string defaultVrootPath, string HostName, string IP, string Port)
{
try
{
ManagementObject oW3SVC = new ManagementObject(_scope, new ManagementPath(@"IIsWebService='W3SVC'"), null);
if (IsWebSiteExists(serverID))
{
throw new ApplicationException("站点已经存在");
}
ManagementBaseObject inputParameters = oW3SVC.GetMethodParameters("CreateNewSite");
ManagementBaseObject[] serverBinding = new ManagementBaseObject[1];
serverBinding[0] = CreateServerBinding(HostName, IP, Port);
inputParameters["ServerComment"] = serverComment;
inputParameters["ServerBindings"] = serverBinding;
inputParameters["PathOfRootVirtualDir"] = defaultVrootPath;
inputParameters["ServerId"] = serverID;
ManagementBaseObject outParameter = null;
outParameter = oW3SVC.InvokeMethod("CreateNewSite", inputParameters, null);
// 启动网站
string serverName = "W3SVC/" + serverID;
ManagementObject webSite = new ManagementObject(_scope, new ManagementPath(@"IIsWebServer='" + serverName + "'"), null);
webSite.InvokeMethod("Start", null);
DirectoryEntry MySite = new DirectoryEntry("IIS://localhost/" + serverName);
MySite.Properties["AuthAnonymous"][0] = true;//允许匿名访问
MySite.Properties["AccessScript"][0] = true;//脚本可执行
MySite.Properties["AspEnableParentPaths"][0] = true;//允许父路径
MySite.CommitChanges();
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message);
}
}