c#读取IIS中的站点相关属性代码
2006-11-22 11:15
676 查看
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string currentServerComment=comboBox1.SelectedItem.ToString();
string currentSiteNum = GetWebSiteNum(currentServerComment);
string rootPath = "IIS://localhost/w3svc";
string currentSitePath =rootPath+"/"+currentSiteNum;
DirectoryEntry siteEntry = new DirectoryEntry(currentSitePath);
string currentServerBindings=siteEntry.Properties["ServerBindings"].Value.ToString();
char[] a=":".ToCharArray();
string [] currentBingdings = null;
currentBingdings=currentServerBindings.Split(a);
string currentServerIP=currentBingdings[0];
string currentServerPort=currentBingdings[1];
string currentServerHeader=currentBingdings[2];
string currentServerHost="";
string currentServerPath="";
foreach (DirectoryEntry child in siteEntry.Children)
{
if((child.SchemaClassName == "IIsWebVirtualDir")&&(child.Name=="root"))
{
currentServerPath = child.Properties["Path"].Value.ToString();
}
}
textBox2.Text=currentServerIP;
textBox3.Text=currentServerPort;
textBox4.Text=currentServerPath;
textBox5.Text=currentServerHeader;
textBox6.Text=currentServerHost;
}
/// <summary>
/// 根据站点名称获取站点标识符
/// </summary>
public string GetWebSiteNum(string siteName)
{
Regex regex = new Regex(siteName);
string tmpStr;
string entPath = "IIS://localhost/w3svc";
DirectoryEntry ent =new DirectoryEntry(entPath);
foreach(DirectoryEntry child in ent.Children)
{
if(child.SchemaClassName == "IIsWebServer")
{
if(child.Properties["ServerBindings"].Value != null)
{
tmpStr = child.Properties["ServerBindings"].Value.ToString();
if(regex.Match(tmpStr).Success)
{
return child.Name;
}
}
if(child.Properties["ServerComment"].Value != null)
{
tmpStr = child.Properties["ServerComment"].Value.ToString();
if(regex.Match(tmpStr).Success)
{
return child.Name;
}
}
}
}
return "";
}
{
string currentServerComment=comboBox1.SelectedItem.ToString();
string currentSiteNum = GetWebSiteNum(currentServerComment);
string rootPath = "IIS://localhost/w3svc";
string currentSitePath =rootPath+"/"+currentSiteNum;
DirectoryEntry siteEntry = new DirectoryEntry(currentSitePath);
string currentServerBindings=siteEntry.Properties["ServerBindings"].Value.ToString();
char[] a=":".ToCharArray();
string [] currentBingdings = null;
currentBingdings=currentServerBindings.Split(a);
string currentServerIP=currentBingdings[0];
string currentServerPort=currentBingdings[1];
string currentServerHeader=currentBingdings[2];
string currentServerHost="";
string currentServerPath="";
foreach (DirectoryEntry child in siteEntry.Children)
{
if((child.SchemaClassName == "IIsWebVirtualDir")&&(child.Name=="root"))
{
currentServerPath = child.Properties["Path"].Value.ToString();
}
}
textBox2.Text=currentServerIP;
textBox3.Text=currentServerPort;
textBox4.Text=currentServerPath;
textBox5.Text=currentServerHeader;
textBox6.Text=currentServerHost;
}
/// <summary>
/// 根据站点名称获取站点标识符
/// </summary>
public string GetWebSiteNum(string siteName)
{
Regex regex = new Regex(siteName);
string tmpStr;
string entPath = "IIS://localhost/w3svc";
DirectoryEntry ent =new DirectoryEntry(entPath);
foreach(DirectoryEntry child in ent.Children)
{
if(child.SchemaClassName == "IIsWebServer")
{
if(child.Properties["ServerBindings"].Value != null)
{
tmpStr = child.Properties["ServerBindings"].Value.ToString();
if(regex.Match(tmpStr).Success)
{
return child.Name;
}
}
if(child.Properties["ServerComment"].Value != null)
{
tmpStr = child.Properties["ServerComment"].Value.ToString();
if(regex.Match(tmpStr).Success)
{
return child.Name;
}
}
}
}
return "";
}
相关文章推荐
- c#读取IIS中的站点相关属性代码
- C#列表所有IIS站点以及相关站点属性
- C#列表所有IIS站点以及相关站点属性
- C#列表所有IIS站点以及相关站点属性
- C#通过XML节点属性/属性值读取写入XML操作代码实例
- C# 创建iis站点以及IIS站点属性,iis不能启动站点
- C# 修改IIS相关设置代码
- C#基础-代码部署数据库及IIS站点
- C#IO 文件读取笔记一(File类和Directory类相关属性,FileInfo类和DirectoryInfo类)
- 编写高质量代码改善C#程序的157个建议——建议147:重构多个相关属性为一个类
- IIS管理站点、子站点、程序池间关系,以及C#代码ServerManager实现根据站点与子站点名称获取程序池
- PowerDesign的Pdm文件读取代码(C#)
- [转]C#反射技术之一读取和设置类的属性
- 利用C#创建 IIS 站点并设置.NET Framework版本为ASP.NET 2.0 的方法(二)
- 依据不同的操作系统读取配置文件/java读取属性文件代码
- IIS代码管理(2):创建应用程序池和属性
- C#操作IIS程序池及站点的创建配置实现代码
- C#中创建、打开、读取、写入、保存Excel的一般性代码
- C# 读取和编辑 MP3 ID3 属性的详细操作和说明 (ID3v2)
- 编写高质量代码改善C#程序的157个建议——建议25:谨慎集合属性的可写操作