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

C# 关于 IIS 5.0 创建站点的问题
要求:window 2000 IIS 5.0 ,每个站点的 应用程序保护等级 为 “高(独立的)”,也就是每个站点以dllhost.exe 进程 独立运行,
请部有哪 位 知道怎么做啊?

------解决方案--------------------
用ADSI接口来做,
因为没有IIS5,给你一段IIS6中建站点的代码
 try
{
DirectoryEntry Service = new DirectoryEntry("IIS://" + MachineName + "/W3SVC");
if (Service == null)
return false;

int Index = int型值(一般取IIS中站点中最大ID加1,这个需要写一个方法;


DirectoryEntry Item = Service.Children.Add(Index.ToString(), "IIsWebServer");
Item.Properties["ServerComment"][0] = 站点名称;
Item.Properties["Serverbindings"].Add(站点IP + ":" + 站点Port + ":" + 站点主机头HostName);
Item.Properties["AccessScript"][0] = true;
Item.Properties["AccessWrite"][0] = true;
Item.Properties["AccessSource"][0] = true;
Item.Properties["AccessRead"][0] = true;
Item.Properties["EnableDirBrowsing"][0] = true;
Item.Properties["DefaultDoc"].Value = "index.html,index.aspx";
Item.Properties["EnableDefaultDoc"][0] = true;
Item.Properties["ScriptMaps"].Value = _GetAspNetVersion(); 
Item.Properties["AppIsolated"][0] = "2";
Item.Properties["AccessExecute"][0] = true;
 
DirectoryEntry root = Item.Children.Add("Root", "IIsWebVirtualDir");
root.Properties["path"][0] = 网站目录Path;
Service.CommitChanges();
Item.CommitChanges();
root.CommitChanges();
root.Invoke("AppCreate2", new object[1] { 2 });
}catch(Exception e)
{
throw(e);
}



#region 获取程序版本设置字符串
/// <summary>
/// 获取程序版本设置字符串
/// </summary>
/// <returns></returns>
private string[] _GetAspNetVersion()
{
string SystemPath = System.Environment.SystemDirectory;
string WindowsPath = _GetParentFolderCode(SystemPath);
string FramworkPath = WindowsPath + @"microsoft.net\framework\v" + System.Environment.Version.ToString(3);

string ScriptMaps = @".asp," + SystemPath + @"\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.cer," + SystemPath + @"\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.cdx," + SystemPath + @"\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.asa," + SystemPath + @"\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
.idc," + SystemPath + @"\inetsrv\httpodbc.dll,5,GET,POST
.shtm," + SystemPath + @"\inetsrv\ssinc.dll,5,GET,POST
.shtml," + SystemPath + @"\inetsrv\ssinc.dll,5,GET,POST
.stm," + SystemPath + @"\inetsrv\ssinc.dll,5,GET,POST
.asax," + FramworkPath + @"\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.ascx," + FramworkPath + @"\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG
.ashx," + FramworkPath + @"\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.asmx," + FramworkPath + @"\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.aspx," + FramworkPath + @"\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG
.axd," + FramworkPath + @"\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG