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 ...
随机推荐
- Convert.ToDateTime(值),方法可以把一个值转化成DateTime类型。
例子:将日历控件的值转化成DateTime类型. DateTime beginDate = Convert.ToDateTime(this.beginCalendar.EditValue);
- 分享一例测试环境下nginx+tomcat的视频业务部署记录
需求说明:在测试环境下(192.168.1.28)部署一套公司某业务环境,其中:该业务前台访问地址: http://testhehe.wangshibo.com该业务后台访问地址: http://te ...
- Python的高级特性2:列表推导式,生成器与迭代器
一.列表推导式 1.列表推导式是颇具python风格的一种写法.这种写法除了高效,也更简短. In [23]: {i:el for i,el in enumerate(["one" ...
- Resting state brain networks derived from spatial ICA - an individual case
Reference: Xin D, Biswal B B. Dynamic brain functional connectivity modulated by resting-state netwo ...
- VS XML注释
1.<c> <c>text</c> 其中: text 希望将其指示为代码的文本. 备注 <c> 标记为您提供了一种将说明中的文本标记为代码的方法.使用 ...
- DocOptimizer 0.9.0 Beta Released
DocOptimizer 是一个文档优化工具,它通过移除Excel中多余的单元格:将嵌入的OLE替换成图片:移除文档中的隐藏信息:优化文档中的图片等等手段,将Office或PDF文件压缩20%-90% ...
- DWZ中Tree树形菜单的treeCheck如何获取返回值解决方案
最近在对DWZ和asp.net MVC3进行整合,其中遇到了很多问题,总算一一解决了,今天就说说题目所示的问题解决方案. 想做一个基于角色的权限管理,要对每一个Action进行权限控制.就想用DWZ的 ...
- 代码滑动panorama-即程序中设置SelectedIndex
我们都知道panorama的SelectedIndex属性是只读的,所以通过修改它,在程序滑动panorama似乎不可能.那么是不是就没有办法了呢?其实我们可以通过设置SelectedItemProp ...
- ReactNative运行提示缺少文件xxxRootView.h解决方法
我们经常在github获取源码后运行会出现缺少 "RCTRootView.h" notfound" 文件的错误,对于这种错误我们怎么解决了. 1.cd到项目根目录 删除项 ...
- git by example
记一次回滚操作 路人甲让我修改一个bug,我在develop下修改了 路人甲让我push到releae/sdk0.7分支上 我本地操作切换到release分支并合并develop上的修改: git c ...