已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C# 操作IIS方法集合如果在win8,win7情况下报错:未知错误(0x80005000)见/ts1030746080/article/details/8741399using System;using System.Collections;using System.Collections.Generic;using System.DirectoryServices;using System.Linq;using System.Net;using System.Text;using System.Threading.Tasks;namespace IISControlHelper / / IIS 操作方法集合 / /ts1030746080/article/details/8741399 错误 / public class IISWorker private static string HostName = localhost; / / 获取本地IIS版本 / / public static string GetIIsVersion() try DirectoryEntry entry = new DirectoryEntry(IIS:/ + HostName + /W3SVC/INFO); string version = entry.PropertiesMajorIISVersionNumber.Value.ToString(); return version; catch (Exception se) /说明一点:IIS5.0中没有(int)entry.PropertiesMajorIISVersionNumber.Value;属性,将抛出异常 证明版本为 5.0 return string.Empty; / / 创建虚拟目录网站 / / 网站名称 / 物理路径 / 站点+端口,如3:90 / 是否创建新的应用程序池 / public static int CreateWebSite(string webSiteName, string physicalPath, string domainPort,bool isCreateAppPool) DirectoryEntry root = new DirectoryEntry(IIS:/ + HostName + /W3SVC); / 为新WEB站点查找一个未使用的ID int siteID = 1; foreach (DirectoryEntry e in root.Children) if (e.SchemaClassName = IIsWebServer) int ID = Convert.ToInt32(e.Name); if (ID = siteID) siteID = ID + 1; / 创建WEB站点 DirectoryEntry site = (DirectoryEntry)root.Invoke(Create, IIsWebServer, siteID); site.Invoke(Put, ServerComment, webSiteName); site.Invoke(Put, KeyType, IIsWebServer); site.Invoke(Put, ServerBindings, domainPort + :); site.Invoke(Put, ServerState, 2); site.Invoke(Put, FrontPageWeb, 1); site.Invoke(Put, DefaultDoc, Default.html); / site.Invoke(Put, SecureBindings, :443:); site.Invoke(Put, ServerAutoStart, 1); site.Invoke(Put, ServerSize, 1); site.Invoke(SetInfo); / 创建应用程序虚拟目录 DirectoryEntry siteVDir = site.Children.Add(Root, IISWebVirtualDir); siteVDir.PropertiesAppIsolated0 = 2; siteVDir.PropertiesPath0 = physicalPath; siteVDir.PropertiesAccessFlags0 = 513; siteVDir.PropertiesFrontPageWeb0 = 1; siteVDir.PropertiesAppRoot0 = LM/W3SVC/ + siteID + /Root; siteVDir.PropertiesAppFriendlyName0 = Root; if (isCreateAppPool) DirectoryEntry apppools = new DirectoryEntry(IIS:/ + HostName + /W3SVC/AppPools); DirectoryEntry newpool = apppools.Children.Add(webSiteName, IIsApplicationPool); newpool.PropertiesAppPoolIdentityType0 = 4; /4 newpool.PropertiesManagedPipelineMode0 = 0; /0:集成模式 1:经典模式 newpool.CommitChanges(); siteVDir.PropertiesAppPoolId0 = webSiteName; siteVDir.CommitChanges(); site.CommitChanges(); return siteID; / / 得到网站的物理路径 / / 网站节点 / public static string GetWebsitePhysicalPath(DirectoryEntry rootEntry) string physicalPath = ; foreach (DirectoryEntry childEntry in rootEntry.Children) if (childEntry.SchemaClassName = IIsWebVirtualDir) & (childEntry.Name.ToLower() = root) if (childEntry.PropertiesPath.Value != null) physicalPath = childEntry.PropertiesPath.Value.ToString(); else physicalPath = ; return physicalPath; / / 获取站点名 / public static List GetServerBindings() List iisList = new List(); string entPath = String.Format(IIS:/0/w3svc, HostName); DirectoryEntry ent = new DirectoryEntry(entPath); foreach (DirectoryEntry child in ent.Children) if (child.SchemaClassName.Equals(IIsWebServer, StringComparison.OrdinalIgnoreCase) if (child.PropertiesServerBindings.Value != null) object objectArr = child.PropertiesServerBindings.Value; string serverBindingStr = string.Empty; if (IsArray(objectArr)/如果有多个绑定站点时 object objectToArr = (object)objectArr; serverBindingStr = objectToArr0.ToString(); else/只有一个绑定站点 serverBindingStr = child.PropertiesServerBindings.Value.ToString(); IISInfo iisInfo = new IISInfo(); iisInfo.DomainPort = serverBindingStr; iisInfo.AppPool = child.PropertiesAppPoolId.Value.ToString();/应用程序池 iisList.Add(iisInfo); return iisList; public static bool CreateAppPool(string appPoolName, string Username, string Password) bool issucess = false; try /创建一个新程序池 DirectoryEntry newpool; DirectoryEntry apppools = new DirectoryEntry(IIS:/ + HostName + /W3SVC/AppPools); newpool = apppools.Children.Add(appPoolName, IIsApplicationPool); /设置属性 访问用户名和密码 一般采取默认方式 newpool.PropertiesWAMUserName0 = Username; newpool.PropertiesWAMUserPass0 = Password; newpool.PropertiesAppPoolIdentityType0 = 3; newpool.CommitChanges(); issucess = true; return issucess; catch / (Exception ex) return false; / / 建立程序池后关联相应应用程序及虚拟目录 / public static void SetAppToPool(string appname,string poolName) /获取目录 DirectoryEntry getdir = new DirectoryEntry(IIS:/localhost/W3SVC); foreach (DirectoryEntry getentity in getdir.Children) if (getentity.SchemaClassName.Equals(IIsWebServer) /设置应用程序程序池 先获得应用程序 在设定应用程序程序池 /第一次测试根目录 foreach (DirectoryEntry getchild in getentity.Children) if (getchild.SchemaClassName.Equals(IIsWebVirtualDir) /找到指定的虚拟目录.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 广东高中学校整改通知书
- 广州国际学校通知书
- 广德长安小区停电通知书
- 广西区大学放假通知书
- 康怡园小区风控通知书
- 延吉东开发区停水通知书
- 延长县停业整顿通知书
- 建设工程停工通知书
- 开发区封路维护通知书
- 开班未请假通知书
- 2025年下半年吉林森工集团松江河林业限公司泉阳林业限公司面向社会公开招聘易考易错模拟试题(共500题)试卷后附参考答案
- 2026年雪茄烟活动策划方案
- 角磨机安全使用培训课件
- 生产管理SOP(标准操作流程)模板
- 2026年浙江中烟工业有限责任公司高层次人才招聘(2人)考试笔试参考题库附答案解析
- 白玉县冬季施工方案
- 2025税务师《税法二》考试试题及参考答案
- 燃气管道保护专业施工方案
- 2026中国能源建设集团云南火电建设有限公司校园招聘(46人)备考考试题库附答案解析
- 2024中国生物医药出海现状与趋势蓝皮书
- DB14T 3563-2025 县域医共体慢病管理中心建设与运行规范
评论
0/150
提交评论