三个文件:
/**/FileName: hostservice.cs
//
using System;
using System.Data;
using Wooyea.WebSite.Modules.Hosts.DataAccess;
using Wooyea.WebSite.Modules.Hosts.Configuration;
namespace Wooyea.WebSite.Modules.Hosts.Business
{
/** <summary>
/// Summary description for HostService.
/// </summary>
public class HostService
{
Private fields#region Private fields
private ModuleSettings settings;
private int id;
private string name;
private string description;
private decimal price; // the field in SQL server is the type of smallmoney
private string ip;
private int port;
private string rootPath;
private int maxBandwidth;
private int maxConnections;
private int cpuLimit;
private byte serverSize;
private byte appIsolated;
#endregion
Properties#region Properties
public int ID
{
get {return id;}
set {id = value;}
}
public string Name
{
get {return name;}
set {name = value;}
}
public string Description
{
get {return description;}
set {description = value;}
}
public decimal Price
{
get {return price;}
set {price = value;}
}
public string IP
{
get {return ip;}
set {ip = value;}
}
public int Port
{
get {return port;}
set {port = value;}
}
public string RootPath
{
get {return rootPath;}
set {rootPath = value;}
}
public int MaxBandwidth
{
get {return maxBandwidth;}
set {maxBandwidth = value;}
}
public int CpuLimit
{
get {return cpuLimit;}
set {cpuLimit = value;}
}
public byte ServerSize
{
get {return serverSize;}
set {serverSize = value;}
}
#endregion
public HostService()
{
Configuration.ModuleConfig config = new ModuleConfig();
settings = config.GetSettings();
}
public HostService(string name, string description, decimal price, string ip, string rootPath) : this()
{
this.name = name;
this.description = description;
this.price = price;
this.ip = ip;
this.rootPath = rootPath;
}
public HostService(int id) : this()
{
this.id = id;
GetDetails();
}
public void GetDetails()
{
DataAccess.HostServices dataHostServices = new Wooyea.WebSite.Modules.Hosts.DataAccess.HostServices(settings.ConnectionString);
DataRow tempRow = dataHostServices.GetDetails(id);
this.name = (string)tempRow["HostServiceName"];
this.price = Convert.ToDecimal(tempRow["HostServicePrice"]);
this.ip = (string)tempRow["HostServiceIP"];
this.port = (int)tempRow["HostServicePort"];
this.rootPath = (string)tempRow["HostServiceRootPath"];
}
public DataSet GetHostServices()
{
DataAccess.HostServices dataHostServices= new Wooyea.WebSite.Modules.Hosts.DataAccess.HostServices(settings.ConnectionString);
return dataHostServices.GetHostServices();
}
public int Create()
{
DataAccess.HostServices dataHostServices= new Wooyea.WebSite.Modules.Hosts.DataAccess.HostServices(settings.ConnectionString);
return dataHostServices.Insert(name, description, price, rootPath, ip);
}
public bool Update()
{
DataAccess.HostServices dataHostServices= new Wooyea.WebSite.Modules.Hosts.DataAccess.HostServices(settings.ConnectionString);
return dataHostServices.Update(id, name, description, price, rootPath, ip);
}
}
}
/**/end hostservice.cs/
// FileName: IISManager.cs
using System;
using System.Collections;
using System.Text.RegularExpressions;
using System.Text;
using System.DirectoryServices;
using Wooyea.WebSite.Modules.Hosts;
namespace Wooyea.WebSite.Modules.Hosts.Business
{
/** <summary>
/// Summary description for Class1.
/// </summary>
class IISManager
{
public IISManager()
{}
public DirectoryEntry GetDirectoryEntry(string entryPath)
{
// creater direntry instance depend on local or remote
DirectoryEntry dirEntry = new DirectoryEntry(entryPath);
return dirEntry;
}
public bool CreateSite(WebSiteInfo newSiteInfo)
{
string entPath = "IIS://localhost/w3svc";
DirectoryEntry rootEntry = GetDirectoryEntry(entPath);
string newSiteID = GetNewSiteID();
DirectoryEntry newSiteEntry = rootEntry.Children.Add(newSiteID, "IIsWebServer");
newSiteEntry.CommitChanges();
newSiteEntry.Properties["ServerBindings"].Value = newSiteInfo.ServerBindings;
newSiteEntry.Properties["ServerComment"].Value = newSiteInfo.Comment;
newSiteEntry.CommitChanges();
DirectoryEntry vDirEntry = newSiteEntry.Children.Add("root", "IIsWebVirtualDir");
vDirEntry.CommitChanges();
vDirEntry.Properties["Path"].Value = newSiteInfo.Path; //ph patth in disk
vDirEntry.CommitChanges();
return true;
}
/** <summary>
/// Get and return a new website ID of specify host
/// </summary>
/// <returns>the smallest new website ID of the host</returns>
public string GetNewSiteID()
{
ArrayList idList = new ArrayList();
string tmpStr;
string entryPath = "IIS://localhost/W3SVC";
DirectoryEntry entry = GetDirectoryEntry(entryPath);
foreach (DirectoryEntry child in entry.Children)
{
if (child.SchemaClassName == "IIsWebServer")
{
tmpStr = child.Name.ToString();
idList.Add(Convert.ToInt32(tmpStr));
}
}
idList.Sort();
int i = 1;
foreach (int id in idList)
{
if (i == id)
{
i++;
}
}
return i.ToString();
}
}
}
/**end IISmanager/
//File Name: WebSite.cs
using System;
using System.DirectoryServices;
using Wooyea.WebSite.Modules.Hosts.Configuration;
using Wooyea.WebSite.Modules.Hosts.Business;
using Wooyea.WebSite.Modules.Hosts.DataAccess;
namespace Wooyea.WebSite.Modules.Hosts.Business
{
/** <summary>
/// Summary description for WebSite.
/// </summary>
public class WebSite
{
Private fields#region Private fields
private ModuleSettings settings;
private WebSiteInfo siteInfo;
#endregion
Properties#region Properties
#endregion
WebSite()
{
Configuration.ModuleConfig config = new ModuleConfig();
settings = config.GetSettings();
}
public WebSite(string newHeader, string newComment, string newIP, int newPort, string newPath) : this()
{
this.siteInfo.Header = newHeader;
this.siteInfo.IP = newIP;
this.siteInfo.Port = newPort;
this.siteInfo.Comment = newComment;
this.siteInfo.Path = newPath;
}
/** <summary>
/// Create a new data record in website table and another one in the cross table
/// </summary>
/// <param name="userID">userID of current priciple</param>
/// <returns></returns>
public int CreateSite(int userID)
{
IISManager iis = new IISManager();
iis.CreateSite(siteInfo);
DataAccess.WebSites newSite = new WebSites(settings.ConnectionString);
return newSite.Add(siteInfo, userID);
}
}
}
详细解决方案
用ADSI控制IIS创建网站, 虚拟目录…… (C#)
热度:89 发布时间:2023-12-13 08:33:42.0
相关解决方案
- 百分求解:在vs2005中.net项目发布到IIS 6下(虚拟目录)但是浏览的时候提示没有访问权限。解决办法
- 什么叫 虚拟目录?(FTP)
- 高分 fso 虚拟目录
- 搜了N变教程,还是没配置好apache 虚拟目录 伪静态,求大家帮忙看下有关问题出在哪
- nginx“虚拟目录”不支持php的解决方法
- 虚拟目录,该怎么处理
- 配备 Tomcat 的网站根目录、虚拟目录、端口等
- ASP.NET 治理网站(虚拟目录)
- word跟excel在网页上显示,文件流,虚拟目录,文件上传
- 搜了N变教程,还是没配置好apache 虚拟目录 伪静态,求大家帮忙看下有关问题出在哪
- nginx“虚拟目录”不支持php的解决方法
- 虚拟目录,该怎么处理
- 用ADSI控制IIS创建网站, 虚拟目录…… (C#)
- asp.net 获得域名,端口,虚拟目录
- XP下的IIS不支持“新建网站”的功能,XP下的IIS只能使用新建“虚拟目录”
- moodle服务器优化,linux服务器优化同理apache nginx tomcat php php-fpm loadruner ab nginx 虚拟目录
- ${pageContext.reuquest.contextPath}虚拟目录
- tomcat配置静态资源路径(虚拟目录)