c# 获取iis地址
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZQNB.Tool.Upgrade.Utilities
{
public class IISHelper
{
/// <summary>
/// 获取指定站名的路径
/// todo 应该做成用户可以选择的
/// </summary>
/// <returns></returns>
public static string GetSitePath()
{
var rootEntry = new DirectoryEntry("IIS://localhost/w3svc");
foreach (DirectoryEntry entry in rootEntry.Children)
{
if (entry.SchemaClassName.Equals("IIsWebServer", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Name: {0}", entry.Name);
Console.WriteLine("Path: {0}", IISWorker.GetWebsitePhysicalPath(entry));
Console.WriteLine("ServerBindings: {0}", entry.Properties["ServerBindings"].Value);
var serverComment = entry.Properties["ServerComment"].Value.ToString();
Console.WriteLine("ServerComment: {0}", serverComment);
if (serverComment == Config.SiteName)
{
return IISWorker.GetWebsitePhysicalPath(entry);
}
//DirectoryEntry virEntry = new DirectoryEntry(entry.Path + "/ROOT");
//foreach (DirectoryEntry entryVirtual in virEntry.Children)
//{
// if (entryVirtual.SchemaClassName.Equals("IIsWebVirtualDir", StringComparison.OrdinalIgnoreCase))
// {
// Console.WriteLine("SchemaClassName: {0}", entryVirtual.SchemaClassName);
// Console.WriteLine("Name: {0}", entryVirtual.Name);
// Console.WriteLine("Path: {0}", entryVirtual.Properties["Path"].Value);
// Console.WriteLine();
// }
//}
}
}
return null;
}
}
public class IISWorker
{
/// <summary>
/// 得到网站的物理路径
/// </summary>
/// <param name="rootEntry">网站节点</param>
/// <returns></returns>
public static string GetWebsitePhysicalPath(DirectoryEntry rootEntry)
{
string physicalPath = "";
foreach (DirectoryEntry childEntry in rootEntry.Children)
{
if ((childEntry.SchemaClassName == "IIsWebVirtualDir") && (childEntry.Name.ToLower() == "root"))
{
if (childEntry.Properties["Path"].Value != null)
{
physicalPath = childEntry.Properties["Path"].Value.ToString();
}
else
{
physicalPath = "";
}
}
}
return physicalPath;
}
}
}
c# 获取iis地址的更多相关文章
- web api 记录部署IIS获取服务器地址的类型
获取服务器地址类型分多种,以下记录 1.HttpContext.Current.Server.MapPath("~/File") 返回的值为 D:\3Project\Code\Mo ...
- [WPF] 浏览百度地图并获取经纬度地址信息
项目中需要利用登记的区域和地址在百度地图上定位,并获取该地址的经纬度. 本次功能对我来说主要难点如下:1.百度地图API的基本使用方法,请首选使用百度地图的JavaScript大众版(PS:之前使用W ...
- PHP获取IP地址的方法,防止伪造IP地址注入攻击
PHP获取IP地址的方法 /** * 获取客户端IP地址 * <br />来源:ThinkPHP * <br />"X-FORWARDED-FOR" 是代理 ...
- 【zabbix】Windows服务器获取IIS站点以及程序池状态
在使用zabbix做Windows服务器监控的时候遇到一个比较棘手的问题,检测IIS站点状态. 普通情况下,只要用浏览器访问iis站点测试一下返回码是不是200即可判断状态,但是我这次遇到的是iis使 ...
- Asp.Net 无法获取IIS拾取目录的解决办法[译]
Asp.Net 无法获取IIS拾取目录的解决办法 作者:Jason Doucette [MCP] 翻译:彭远志 原文地址:Fixing the cannot get IIS pickup direc ...
- Atitit onvif协议获取rtsp地址播放java语言 attilx总结
Atitit onvif协议获取rtsp地址播放java语言 attilx总结 1.1. 获取rtsp地址的算法与流程1 1.2. Onvif摄像头的发现,ws的发现机制,使用xcf类库1 2. 调用 ...
- windows下获取IP地址的两种方法
windows下获取IP地址的两种方法: 一种可以获取IPv4和IPv6,但是需要WSAStartup: 一种只能取到IPv4,但是不需要WSAStartup: 如下: 方法一:(可以获取IPv4和I ...
- 【PHP开发篇】一个统计客户端商机提交的获取IP地址
1.对客服提交数据的ip地址记录. 获取ip地址的方法: public function getIP() { global $ip; if (getenv("HTTP_X_REAL_IP&q ...
- 获取 IP 地址
package j2se.core.net.base; import java.net.InetAddress;import java.net.UnknownHostException; public ...
随机推荐
- Location of several networks in brain
Source: Naci, L., et al. (2014). "A common neural code for similar conscious experiences in dif ...
- SQL SERVER 系统库查询
本文内容主要来自网络,如有错误请路过的大牛指点迷津. 1.sqlserver 数据库最大并发连接数 sqlserver的最大连接数虽然说是不限制,但实际的限制数量是32767,如果需要超出这个数量,一 ...
- SQL Server 2005、2008 的 datetime 值范围(转)
SQL Server 2005.2008 的 datetime 最小值是:1753-01-01 00:00:00 最大值是:9999-12-31 23:59:59.997 这与 .NET 中的 Dat ...
- 微软职位内部推荐-SDEII_ ECO
微软近期Open的职位: SDE II SDE II Organization Summary: Engineering, Customer interactions & Online (EC ...
- 由于 ASP.NET 进程标识对全局程序集缓存没有读权限,因此未能执行请求。错误: 0x80131902
由于 ASP.NET 进程标识对全局程序集缓存没有读权限,因此未能执行请求.错误: 0x80131902 分类: c#2013-06-17 10:22 89人阅读 评论(0) 收藏 举报 ASP.NE ...
- Core Web API上使用Swagger提供API文档
在ASP.NET Core Web API上使用Swagger提供API文档 我在开发自己的博客系统(http://daxnet.me)时,给自己的RESTful服务增加了基于Swagger的AP ...
- Java的注解(Annotation)
1.什么是注解 Annotation is code about the code, that is metadata about the program itself. Java注解,是Java5. ...
- Eclipse设置和必装插件
文章长期更新,主要是记录Eclipse好用的插件和规范的设置 插件篇: 1. StartExplorer. 在Eclipse内定位项目目录,和打开项目目录下的命令行,总是非常麻烦.有了这个插件以后,这 ...
- stm32调试记录一
..\..\SYSTEM\usart\usart.c(1): error: #5: cannot open source input file "sys.h": No such ...
- HDU2444-The Accomodation of Students-判断是否为二分图+ISAP
要先判断是不是二分图.用黑白染色法. 遇到已经染过的跟当前的颜色相同时就说明不是二分图,也即出现了奇环 /*---------------------------------------------- ...