#region 新建立一个IISWEB站点 ///<summary> ///添加一个站点 ///</summary> public string CreateWebSite() { int siteID = int.Parse(GetNewWebSiteID()); try { root = new DirectoryEntry("IIS://" + this._server + "/W3SVC"); if (EnsureNewSiteEnavaible(this._serverip + ":" + this._port + ":" + this._domain) || EnsureNewSiteEnavaible(this._server + ":" + this._port + ":" + this._domain)) { return "该站点已经存在,请重新命名站点!"; } else { DirectoryEntry site = (DirectoryEntry)root.Invoke("Create", "IIsWebServer", siteID); site.Invoke("Put", "ServerComment", this._webSiteName); site.Invoke("Put", "KeyType", "IIsWebServer"); site.Invoke("Put", "ServerBindings", this._serverip + ":" + this._port + ":" + this._domain); site.Invoke("Put", "ServerState", 2); site.Invoke("Put", "FrontPageWeb", 1); site.Invoke("Put", "DefaultDoc", "default.aspx,index.aspx,index.html,index.htm,default.htm,default.html"); site.Invoke("Put", "ServerAutoStart", 1); site.Invoke("Put", "ServerSize", 1); site.Invoke("SetInfo"); site.CommitChanges(); root.CommitChanges(); DirectoryEntry siteVDir = site.Children.Add("Root", "IISWebVirtualDir"); siteVDir.Properties["AppIsolated"][0] = 2; siteVDir.Properties["Path"][0] = this._path; siteVDir.Properties["AccessFlags"][0] = 513; siteVDir.Properties["FrontPageWeb"][0] = 1; siteVDir.Properties["AppRoot"][0] = string.Format("/LM/W3SVC/{0}/Root", siteID); siteVDir.Properties["AppFriendlyName"][0] = "默认应用程序"; PropertyValueCollection propValues = siteVDir.Properties["MimeMap"]; IISOle.MimeMapClass newMimeType = new IISOle.MimeMapClass(); newMimeType.Extension = ".flv"; newMimeType.MimeType = "flv-application/octet-stream"; propValues.Add(newMimeType); string strerror = @"400,*,FILE,C:\WINDOWS\help\iisHelp\common\400.htm" + @" 401,1,FILE,C:\WINDOWS\help\iisHelp\common\401-1.htm" + @" 401,2,FILE,C:\WINDOWS\help\iisHelp\common\401-2.htm" + @" 401,3,FILE,C:\WINDOWS\help\iisHelp\common\401-3.htm" + @" 401,4,FILE,C:\WINDOWS\help\iisHelp\common\401-4.htm" + @" 401,5,FILE,C:\WINDOWS\help\iisHelp\common\401-5.htm" + @" 401,7,FILE,C:\WINDOWS\help\iisHelp\common\401-1.htm" + @" 403,1,FILE,C:\WINDOWS\help\iisHelp\common\403-1.htm" + @" 403,2,FILE,C:\WINDOWS\help\iisHelp\common\403-2.htm" + @" 403,3,FILE,C:\WINDOWS\help\iisHelp\common\403-3.htm" + @" 403,4,FILE,C:\WINDOWS\help\iisHelp\common\403-4.htm" + @" 403,5,FILE,C:\WINDOWS\help\iisHelp\common\403-5.htm" + @" 403,6,FILE,C:\WINDOWS\help\iisHelp\common\403-6.htm" + @" 403,7,FILE,C:\WINDOWS\help\iisHelp\common\403-7.htm" + @" 403,8,FILE,C:\WINDOWS\help\iisHelp\common\403-8.htm" + @" 403,9,FILE,C:\WINDOWS\help\iisHelp\common\403-9.htm" + @" 403,10,FILE,C:\WINDOWS\help\iisHelp\common\403-10.htm" + @" 403,11,FILE,C:\WINDOWS\help\iisHelp\common\403-11.htm" + @" 403,12,FILE,C:\WINDOWS\help\iisHelp\common\403-12.htm" + @" 403,13,FILE,C:\WINDOWS\help\iisHelp\common\403-13.htm" + @" 403,15,FILE,C:\WINDOWS\help\iisHelp\common\403-15.htm" + @" 403,16,FILE,C:\WINDOWS\help\iisHelp\common\403-16.htm" + @" 403,17,FILE,C:\WINDOWS\help\iisHelp\common\403-17.htm" + @" 403,18,FILE,C:\WINDOWS\help\iisHelp\common\403.htm" + @" 403,19,FILE,C:\WINDOWS\help\iisHelp\common\403.htm" + @" 403,20,FILE,C:\WINDOWS\help\iisHelp\common\403-20.htm" + @" 404,*,URL,/404.aspx" + @" 404,2,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm" + @" 404,3,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm" + @" 405,*,FILE,C:\WINDOWS\help\iisHelp\common\405.htm" + @" 406,*,FILE,C:\WINDOWS\help\iisHelp\common\406.htm" + @" 407,*,FILE,C:\WINDOWS\help\iisHelp\common\407.htm" + @" 412,*,FILE,C:\WINDOWS\help\iisHelp\common\412.htm" + @" 414,*,FILE,C:\WINDOWS\help\iisHelp\common\414.htm" + @" 415,*,FILE,C:\WINDOWS\help\iisHelp\common\415.htm" + @" 500,12,FILE,C:\WINDOWS\help\iisHelp\common\500-12.htm" + @" 500,13,FILE,C:\WINDOWS\help\iisHelp\common\500-13.htm" + @" 500,15,FILE,C:\WINDOWS\help\iisHelp\common\500-15.htm" + @" 500,16,FILE,C:\WINDOWS\help\iisHelp\common\500.htm" + @" 500,17,FILE,C:\WINDOWS\help\iisHelp\common\500.htm" + @" 500,18,FILE,C:\WINDOWS\help\iisHelp\common\500.htm" + @" 500,19,FILE,C:\WINDOWS\help\iisHelp\common\500.htm"; string[] strerrorlist = strerror.Split(' '); siteVDir.Properties["HttpErrors"].Value = strerrorlist; siteVDir.Invoke("AppCreate", true); root.CommitChanges(); siteVDir.CommitChanges(); site.CommitChanges(); return "创建站点成功!"; } } catch (Exception ex) { return ex.Message; } } #endregion