【asp源码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。
网学会员整理了asp源码-C#操作IIS7程序池新建站点站点配置 - 其它资料的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
最近在做一个 WEB 程序的安装包;对一些操作 IIS 进行一个简单的总结;主要包括对 IIS 进行站点的新建以及新建站点的 NET 版本的选择,还有针对 IIS7 程序池的托管模式以及版本的操作;首先要对 Microsoft.Web.Administration 进行引用,它主要是用来操作 IIS7; using System.DirectoryServicesusing Microsoft.Web.Administration 1:首先是对本版 IIS 的版本进行配置:DirectoryEntry getEntity newDirectoryEntryIIS://localhost/W3SVC/INFO string Version getEntity.PropertiesMajorIISVersionNumber.Value.ToString MessageBox.ShowIIS 版本为: Version 2:是判断程序池是存在; /// /// 判断程序池是否存在 /// ///程序池名称 /// true 存在 false 不存在 private bool IsAppPoolNamestring AppPoolName bool result false DirectoryEntry appPools newDirectoryEntryIIS://localhost/W3SVC/AppPools foreach DirectoryEntry getdir in appPools.Children if getdir.Name.EqualsAppPoolName result true return result 3:删除应用程序池 /// /// 删除指定程序池 /// ///程序池名称 /// true 删除成功 false 删除失败 private bool DeleteAppPoolstring AppPoolName bool result false DirectoryEntry appPools newDirectoryEntryIIS://localhost/W3SVC/AppPools foreach DirectoryEntry getdir in appPools.Children if getdir.Name.EqualsAppPoolName try getdir.DeleteTree result true catch result false return result 4:创建应用程序池 (对程序池的设置主要是针对 IIS7;IIS7 应用程序池托管模式主要包括集成跟经典模式,并进行 NET 版本的设置) string AppPoolName LamAppPool if IsAppPoolNameAppPoolName DirectoryEntry newpool DirectoryEntry appPools newDirectoryEntryIIS://localhost/W3SVC/AppPools newpool appPools.Children.AddAppPoolNameIIsApplicationPool newpool.CommitChanges MessageBox.ShowAppPoolName 程序池增加成功 endregion region 修改应用程序的配置包含托管模式及其 NET 运行版本 ServerManager sm new ServerManager sm.ApplicationPoolsAppPoolName.ManagedRuntimeVersion v4.0 sm.ApplicationPoolsAppPoolName.ManagedPipelineMode ManagedPipelineMode.Classic //托管模式 Integrated 为集成 Classic 为经典 sm.CommitChanges MessageBox.ShowAppPoolName 程序池托管管道模式: sm.ApplicationPoolsAppPoolName.ManagedPipelineMode.ToString 运行的 NET 版本为: sm.ApplicationPoolsAppPoolName.ManagedRuntimeVersion 运用 C代码来对 IIS7 程序池托管管道模式及版本进行修改; 针 5: 对 IIS6 的 NET 版进行设置因为此处我是用到 NET4.0 所以 V4.0.30319 若是 NET2.0 则在这进行修改 v2.0.50727 //启动 aspnet_regiis.exe 程序 string fileName Environment.GetEnvironmentVariablewindir Microsoft.NETFrameworkv4.0.30319aspnet_regiis.exe ProcessStartInfo startInfo newProcessStartInfofileName //处理目录路径 string path vdEntry.Path.ToUpper int index path.IndexOfW3SVC path path.Remove0 index //启动 ASPnet_iis.exe 程序刷新脚本映射 startInfo.Arguments -s path startInfo.WindowStyle ProcessWindowStyle.Hidden startInfo.UseShellExecute false startInfo.CreateNoWindow true startInfo.RedirectStandardOutput true startInfo.RedirectStandardError true Process process new Process process.StartInfo startInfo process.Start process.WaitForExit string errors process.StandardError.ReadToEnd 6:平常我们可能还得对 IIS 中的 MIME 类型进行增加;下面主要是我们用