public List<CustomErrorPage> SiteErrorPageGet(string siteName) { Site site = _serverManager.Sites[siteName]; if (site == null) { throw new Exception(string.Format("站点{0}不存在!", siteName)); } Configuration siteConfig = site.GetWebConfiguration(); ConfigurationSection httpErrorsSection = siteConfig.GetSection("system.webServer/httpErrors"); ConfigurationElementCollection httpErrorsElement = httpErrorsSection.GetCollection(); List<CustomErrorPage> listCustomErrorPage = new List<CustomErrorPage>(); foreach (ConfigurationElement element in httpErrorsElement) { CustomErrorPage customErrorPage = new CustomErrorPage(); customErrorPage.StatusCode = Convert.ToInt32(element["statusCode"]); customErrorPage.CustomerWebRelativePath = element["path"].ToString(); listCustomErrorPage.Add(customErrorPage); } return listCustomErrorPage; }
public string SiteErrorPageSet(DeveloperInfo developerInfo, string siteName, int appId, string errorPage) { List<CustomErrorPage> listCustomErrorPage = new List<CustomErrorPage>(); if (!string.IsNullOrEmpty(errorPage.Trim())) { string[] pages = errorPage.Split(new char[] { '|' }, StringSplitOptions.None); foreach (string page in pages) { string[] errorRecord = page.Replace(",", ",").Split(new char[] { ',' }, StringSplitOptions.None); CustomErrorPage customErrorPage = new CustomErrorPage(); customErrorPage.StatusCode = int.Parse(errorRecord[0].Trim()); customErrorPage.CustomerWebRelativePath = errorRecord[1].Trim(); listCustomErrorPage.Add(customErrorPage); } } IISProcess iisProcess = new IISProcess(DeveloperConfig.SystemPhysicalPath, developerInfo.LoginName); iisProcess.SiteErrorPageSet(siteName, listCustomErrorPage); DbCommand cmd = _dataBaseAccess.CreateCommand(); cmd.CommandText = "Proc_Apps_SiteErrorPage_Update"; DbParameter param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@AppId"; param.DbType = DbType.Int32; param.Value = appId; cmd.Parameters.Add(param); param = _dataBaseAccess.CreateParameter(); param.ParameterName = "@CustomErrorPage"; param.DbType = DbType.String; param.Value = errorPage; cmd.Parameters.Add(param); _dataBaseAccess.ExecuteCommand(cmd); return string.Empty; }