///// <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> /// 设置文件夹权限 处理给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> /// 创建网站 /// </summary> /// <param name="siteInfo"></param> /// <param name="type"></param> /// <param name="netV"></param> public DirectoryEntry CreatNewWeb(NewWebSiteInfo siteInfo, ModelType type = ModelType.集成, NetVersion netV = NetVersion.v4_0) { 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.DefaultPage); //设置默认文档 //创建虚拟目录 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); }