C# 修改IIS相关设置代码
来源:互联网 发布:怎么租淘宝店 编辑:程序博客网 时间:2024/06/06 13:20
/// <summary>
/// 从IIS中查找虚拟目录
/// </summary>
/// <param name="prj">虚拟目录名称</param>
/// <returns></returns>
public static System.DirectoryServices.DirectoryEntry FindVirDir( string VirDirName)
{
System.DirectoryServices.DirectoryEntry rlst = null;
//当项目在IIS上打开时,要把URL转换为物理路径
if (prjname.ToLower().IndexOf("http://") >= 0)
{
System.DirectoryServices.DirectoryEntry rootEntry = new System.DirectoryServices.DirectoryEntry("IIS://localhost/w3svc");
int siteID = 1;
bool isFound = false;
//得到现有的站点标识
foreach (System.DirectoryServices.DirectoryEntry entry in rootEntry.Children)
{
if (entry.SchemaClassName == "IIsWebServer")
{
int ID = Convert.ToInt32(entry.Name);
//查找IIS的根目录
System.DirectoryServices.DirectoryEntry root = entry.Children.Find("root", "IIsWebVirtualDir");
if (ID >= siteID)
{
foreach (System.DirectoryServices.DirectoryEntry centry in root.Children)
{
if (centry.SchemaClassName == "IIsWebVirtualDir")
{
if (centry.Properties["AppFriendlyName"].Value.ToString().ToLower() == VirDirName.ToLower())
{
rlst = centry;
isFound = true;
break;
}
}
}
if (isFound)
{
break;
}
}
}
}
}
else
{
rlst = prjname;
}
return rlst;
}
//创建虚拟目录
//新建虚拟目录的DirectoryEntry对象
System.DirectoryServices.DirectoryEntry tbEntry = root.Children.Add("虚拟目录名称", root.SchemaClassName);
tbEntry.Properties["Path"][0] =PATH; //设置虚拟目录的本地物理路径;
tbEntry.Invoke("AppCreate", true); //设置是否要创建新的虚似目录
tbEntry.Properties["AccessRead"][0] = true;
tbEntry.Properties["ContentIndexed"][0] = true; ;
//设置虚拟目录默认首页
tbEntry.Properties["DefaultDoc"][0] = "index.asp,Default.asp,Default.aspx,index.aspx,login.aspx,login.asp";
tbEntry.Properties["AppFriendlyName"][0] = "虚拟目录名称" ;
tbEntry.Properties["AccessScript"][0] = true; //
tbEntry.Properties["DontLog"][0] = true;
tbEntry.Properties["AuthFlags"][0] = 0;
tbEntry.Properties["AuthFlags"][0] = 1;
tbEntry.Properties["AspEnableParentPaths"][0]=true; //是否支持父路径
tbEntry.CommitChanges(); //提交
- C# 修改IIS相关设置代码
- c#读取IIS中的站点相关属性代码
- IIS 出错 修改相关配置
- C#操作IIS代码
- C#操作IIS代码
- C#操作IIS代码
- C#操作IIS代码
- IIS 部署MVC相关设置
- IIS权限设置的安全相关设置
- IIS权限设置的安全相关设置
- C#操作IIS的代码
- wmi创建IIS c#代码
- C#操作IIS的代码
- wmi创建IIS c#代码
- C#操作IIS的代码
- C#操作IIS的代码
- win7 64bit IIS相关设置
- C# 修改APPconfig设置
- 记录那些曾经让我痛苦的问题
- Joomla模板下载网站阅兵式
- 线程基础知识
- sof和pof配置文件
- VC实现线程池
- C# 修改IIS相关设置代码
- c# 事件,vs2010的样例
- volatile
- C#判断字符串中是否有中文
- SQL2000/2005字符串拆分为列表通用函数
- 免安装版的Tomcat设置开机自启动
- 84827046
- 调试
- Linux内核源码阅读之内存映射篇