社区
C#
帖子详情
如何实现下列功能?
f_h_x_
2004-12-01 05:33:54
C#如何操作IIS?如何用代码建虚拟目录?
在线等>分不够再加.
...全文
55
4
打赏
收藏
如何实现下列功能?
C#如何操作IIS?如何用代码建虚拟目录? 在线等>分不够再加.
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
沈逸
2004-12-01
打赏
举报
回复
public static bool EnsureNewSiteEnavaible(string bindStr)
{
string entPath = String.Format("IIS://{0}/w3svc", HostName);
DirectoryEntry ent = GetDirectoryEntry(entPath);
foreach(DirectoryEntry child in ent.Children)
{
if(child.SchemaClassName == "IIsWebServer")
{
if(child.Properties["ServerBindings"].Value != null)
{
if(child.Properties["ServerBindings"].Value.ToString() == bindStr)
{
return false;
}
}
}
}
return true;
}
#endregion
#region 获取一个网站编号的方法
/// <summary>
/// 获取一个网站的编号。根据网站的ServerBindings或者ServerComment来确定网站编号
/// </summary>
/// <param name="siteName"></param>
/// <returns>返回网站的编号</returns>
/// <exception cref="NotFoundWebSiteException">表示没有找到网站</exception>
public static string GetWebSiteNum(string siteName)
{
Regex regex = new Regex(siteName);
string tmpStr;
string entPath = String.Format("IIS://{0}/w3svc", HostName);
DirectoryEntry ent = GetDirectoryEntry(entPath);
foreach(DirectoryEntry child in ent.Children)
{
if(child.SchemaClassName == "IIsWebServer")
{
if(child.Properties["ServerBindings"].Value != null)
{
tmpStr = child.Properties["ServerBindings"].Value.ToString();
if(regex.Match(tmpStr).Success)
{
return child.Name;
}
}
if(child.Properties["ServerComment"].Value != null)
{
tmpStr = child.Properties["ServerComment"].Value.ToString();
if(regex.Match(tmpStr).Success)
{
return child.Name;
}
}
}
}
throw new NotFoundWebSiteException("没有找到我们想要的站点" + siteName);
}
#endregion
沈逸
2004-12-01
打赏
举报
回复
/// <summary>
/// 删除一个网站。根据网站名称删除。
/// </summary>
/// <param name="siteName">网站名称</param>
public static void DeleteWebSiteByName(string siteName)
{
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
string rootPath = String.Format("IIS://{0}/w3svc", HostName);
DirectoryEntry rootEntry = GetDirectoryEntry(rootPath);
rootEntry.Children.Remove(siteEntry);
rootEntry.CommitChanges();
}
#endregion
#region Start和Stop网站的方法
public static void StartWebSite(string siteName)
{
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
siteEntry.Invoke("Start", new object[] {});
}
public static void StopWebSite(string siteName)
{
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
siteEnt
沈逸
2004-12-01
打赏
举报
回复
public static DirectoryEntry GetDirectoryEntry(string entPath)
{
DirectoryEntry ent;
if(UserName == null)
{
ent = new DirectoryEntry(entPath);
}
else
{
// ent = new DirectoryEntry(entPath, HostName+"\\"+UserName, Password, AuthenticationTypes.Secure);
ent = new DirectoryEntry(entPath, UserName, Password, AuthenticationTypes.Secure);
}
return ent;
}
#region 添加,删除网站的方法
/// <summary>
/// 创建一个新的网站。根据传过来的信息进行配置
/// </summary>
/// <param name="siteInfo">存储的是新网站的信息</param>
public static void CreateNewWebSite(NewWebSiteInfo siteInfo)
{
if(! EnsureNewSiteEnavaible(siteInfo.BindString))
{
throw new DuplicatedWebSiteException("已经有了这样的网站了。" + Environment.NewLine + siteInfo.BindString);
}
string entPath = String.Format("IIS://{0}/w3svc", HostName);
DirectoryEntry rootEntry = GetDirectoryEntry(entPath);
string newSiteNum = GetNewWebSiteID();
DirectoryEntry newSiteEntry = rootEntry.Children.Add(newSiteNum, "IIsWebServer");
newSiteEntry.CommitChanges();
newSiteEntry.Properties["ServerBindings"].Value = siteInfo.BindString;
newSiteEntry.Properties["ServerComment"].Value = siteInfo.CommentOfWebSite;
newSiteEntry.CommitChanges();
DirectoryEntry vdEntry = newSiteEntry.Children.Add("root", "IIsWebVirtualDir");
vdEntry.CommitChanges();
vdEntry.Properties["Path"].Value = siteInfo.WebPath;
vdEntry.CommitChanges();
}
nga96
2004-12-01
打赏
举报
回复
分太少了些吧,呵
代码我有,不知如何给你呢
C //习题 7.14 输入10个学生5门课的成绩,分别用函数
实现
下列
功能
:1.计算每个学生的平均分;2.计算每门课的平均分;3.找出所有50个分数中最高的分数所对应的学生和课程;4.计算平均分方差。
【代码】C //习题 7.14 输入10个学生5门课的成绩,分别用函数
实现
下列
功能
:1.计算每个学生的平均分;2.计算每门课的平均分;3.找出所有50个分数中最高的分数所对应的学生和课程;4.计算平均分方差。
编写一个程序,
实现
下列
功能
编写一个程序,
实现
下列
功能
: 测试两个字符串String str1="It is"和String str2="It is"是否相等 将" a book"与其中的str1字符串连接 用m替换新字符串中的i public static void main(String[] args) { String ...
7.14 输入10个学生5门课程的成绩,分别用函数
实现
下列
功能
7.14 输入10个学生5门课程的成绩,分别用函数
实现
下列
功能
:1.计算每个学生的平均分;2.计算没门课的平均分;3.找出所有50个分数中最高的分数所对应的学生的课程;4.计算平均分方差:其中,xi为某一学生的平均分。...
输入 5 个学生 4 门课的成绩,分别用函数
实现
下列
功能
:
4.输入 5 个学生 4 门课的成绩,分别用函数
实现
下列
功能
: ① 计算每个学生的平均分; ② 计算每门课的平均分; ③ 找出所有 20 个分数中最高的分数所对应的学生和课程; ④ 计算平均分方差 #include<stdio.h>...
编写一个Java应用程序,
实现
下列
功能
: ●程序随机分配给客户一个1~100之间的整数。
编写一个Java应用程序,
实现
下列
功能
: ●程序随机分配给客户一个1~100之间的整数。 ●用户在输入对话框中输入自己的猜测。 ●程序返回提示信息,提示信息分别是:“猜大了”、“猜小了”和“猜对了”。 ●用户可根据...
C#
110,537
社区成员
642,578
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章