/// <summary> /// 设置文件夹权限 处理给EVERONE赋予所有权限 /// </summary> /// <param name="FileAdd">文件夹路径</param> public void SetFileRole(newWebSiteInfo siteInfo) { DirectoryInfo dir_info = new DirectoryInfo(siteInfo.webPath); DirectorySecurity dir_security = new DirectorySecurity(); dir_security.AddAccessRule(new FileSystemAccessRule("Everyone ", FileSystemRights.WriteData, AccessControlType.Allow)); dir_info.SetAccessControl(dir_security); }
/// <summary> /// 设置站点新增自定义mime类型,一次添加一个类型 /// </summary> /// <param name="siteInfo"></param> /// <param name="mysiteServer"></param> public void addMIMEtype(newWebSiteInfo siteInfo, DirectoryEntry mysiteServer) { //需要添加新的mime类型 if (siteInfo.newMimeType.Count > 0) { IISOle.MimeMapClass NewMime = new IISOle.MimeMapClass(); NewMime.Extension = siteInfo.newMimeType.Keys.ToString(); NewMime.MimeType = siteInfo.newMimeType.Values.ToString(); IISOle.MimeMapClass TwoMime = new IISOle.MimeMapClass(); mysiteServer.Properties["MimeMap"].Add(NewMime); mysiteServer.CommitChanges(); } }
/// <summary> /// 创建网站 /// </summary> /// <param name="siteInfo"></param> public DirectoryEntry creatNewWeb(newWebSiteInfo siteInfo, modelType type, netVersion netV) { DirectoryEntry Services = new DirectoryEntry("IIS://localhost/W3SVC"); int webID = 0; foreach (DirectoryEntry server in Services.Children) { if (server.SchemaClassName == "IIsWebServer") { if (Convert.ToInt32(server.Name) > webID) { webID = Convert.ToInt32(server.Name); } } } webID++; //创建站点 DirectoryEntry mySitServer = Services.Children.Add(webID.ToString(), "IIsWebServer"); mySitServer.Properties["ServerComment"].Clear(); mySitServer.Properties["ServerComment"].Add(siteInfo.webName); mySitServer.Properties["Serverbindings"].Clear(); mySitServer.Properties["Serverbindings"].Add(":" + siteInfo.porNum + ":"); mySitServer.Properties["Path"].Clear(); //注意该path为站点的路径,新增站点时,两者目录一致 mySitServer.Properties["path"].Add(siteInfo.webPath); mySitServer.Properties["DefaultDoc"].Add(siteInfo.defoultPage); //设置默认文档 //创建虚拟目录 DirectoryEntry root = mySitServer.Children.Add("Root", "IIsWebVirtualDir"); root.Properties["path"].Clear();//该路劲属性是站点下虚拟路径的路径,类似于站点的子路径 root.Properties["path"].Add(siteInfo.visualPath); if (string.IsNullOrEmpty(siteInfo.appName)) { root.Invoke("appCreate", 0); } else { //创建引用程序池 string appPoolName = siteInfo.appName; if (!isAppPoolExist(appPoolName)) { DirectoryEntry newpool; DirectoryEntry appPools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools"); newpool = appPools.Children.Add(appPoolName, "IIsApplicationPool"); newpool.CommitChanges(); } //修改应用程序池配置 setModalAndNetVersionOfappPool(appPoolName, type, netV); root.Invoke("appCreate3", 0, appPoolName, true); } root.Properties["AppFriendlyName"].Clear(); root.Properties["AppIsolated"].Clear(); root.Properties["AccessFlags"].Clear(); root.Properties["FrontPageWeb"].Clear(); root.Properties["AppFriendlyName"].Add(root.Name); root.Properties["AppIsolated"].Add(2); root.Properties["AccessFlags"].Add(513); root.Properties["FrontPageWeb"].Add(1); root.CommitChanges(); mySitServer.CommitChanges(); return(mySitServer); }