日期:2014-05-18  浏览次数:20474 次

如何得到程序运行站点的主机头信息?
如何得到程序所带站点的IIS的主机头信息?

------解决方案--------------------
this.Request.UserHostAddress
this.Request.UserHostName
------解决方案--------------------
http://www.wakelion.cn/article.asp?id=93
这里有你想要的
------解决方案--------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.DirectoryServices;
using System.Reflection;
using System.Text.RegularExpressions;


--------------------------

int TotalServerCount=0;

DirectoryEntry rootfolder = new DirectoryEntry( "IIS://localhost/W3SVC ");
//TotalServerCount=rootfolder.Children.SchemaFilter.Count;

foreach (DirectoryEntry child in rootfolder.Children)
{
if (child.SchemaClassName == "IIsWebServer ")
{
TotalServerCount+=1;
}
}
//循环获取所有站点详细属性写入数组中
string [] arrayServerID = new string[TotalServerCount];//站点标识符
string [] arrayServerIP = new string[TotalServerCount];//站点主机头
string [] arrayServerPort = new string[TotalServerCount];//站点主机头
string [] arrayServerHeader = new string[TotalServerCount];//站点主机头
string [] arrayServerPath = new string[TotalServerCount];//站点主机头
string [] arrayServerComment = new string[TotalServerCount];//站点主机头

string [] arrayServerBinds = new string[TotalServerCount];//站点主机头


string currentServerBindings;//绑定主机头IP端口字符串
char[] a= ": ".ToCharArray();
string [] currentBingdings =new string[2];

int i=0;
foreach (DirectoryEntry child in rootfolder.Children)
{
if (child.SchemaClassName == "IIsWebServer ")
{
arrayServerID.SetValue(child.Name.ToString(),i);
arrayServerComment.SetValue(child.Properties[ "ServerComment "].Value.ToString(),i);

currentServerBindings=child.Properties[ "ServerBindings "].Value.ToString();

currentBingdings=currentServerBindings.Split(a);

arrayServerIP.SetValue(currentBingdings[0],i);
arrayServerPort.SetValue(currentBingdings[1],i);
arrayServerHeader.SetValue(currentBingdings[2],i);


foreach (DirectoryEntry rootChild in child.Children)
{
if((rootChild.SchemaClassName == "IIsWebVirtualDir ")&&(rootChild.Name.ToString()== "root "))
{
if(rootChild.Properties[ "Path "].Value==null)
{
arrayServerPath.SetValue( " ",i);
}
else
{
arrayServerPath.SetValue(rootChild.Properties[ "Path "].Value.ToString(),i);
}
}
}

i+=1;
}
}
------解决方案--------------------
mark
------解决方案--------------------
用黑客工具