基本信息
源码名称:C#做的 IIS多站点管理 附项目完整源码
源码大小:0.11M
文件格式:.rar
开发语言:C#
更新时间:2013-11-01
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 10 元×
微信扫码支付:10 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
可以创建并获取IIS站点,以及常用的iis操作
可以创建并获取IIS站点,以及常用的iis操作
/// <summary>
/// 创建网站
/// </summary>
/// <param name="strPort"></param>
/// <param name="strSiteName"></param>
/// <param name="strFilePath"></param>
/// <returns></returns>
private DirectoryEntry CreateNewSite(string strSiteName, string strFilePath)
{
try
{
strSitePort = GetNewSitePort();
DirectoryEntry deyRoot = new DirectoryEntry("IIS://localhost/w3svc");
DirectoryEntry siteEntry = deyRoot.Children.Add(GetNewWebSiteID(), "IIsWebServer");
siteEntry.Properties["ServerComment"].Value = strSiteName;
siteEntry.Properties["ServerBindings"].Value = String.Format("{0}:{1}:{2}", "", strSitePort, "");
siteEntry.Properties["ServerAutoStart"].Value = true;
//添加虚拟目录,网站本身没有路径,默认的路径即名称为Root的虚拟目录
DirectoryEntry rootEntry = siteEntry.Children.Add("Root", "IIsWebVirtualDir");
rootEntry.Properties["Path"].Value = strFilePath; //文件夹路径
rootEntry.Properties["AccessRead"][0] = true; //读取权限
rootEntry.Properties["AccessExecute"][0] = false; //执行(如ISAPI应用程序或CGI)
rootEntry.Properties["AccessWrite"][0] = true; //写入
rootEntry.Properties["AccessScript"][0] = true; //执行脚本(如ASP)
rootEntry.Properties["EnableDirBrowsing"][0] = true; //浏览
rootEntry.Properties["DefaultDoc"][0] = "UserLogin.aspx,Default.aspx"; //设置默认文档,多值情况下中间用逗号分割
rootEntry.CommitChanges(); siteEntry.CommitChanges(); return rootEntry;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString() "站点创建失败!"); return null;
}
}
/// <summary>
/// 创建虚拟目录
/// </summary>
/// <param name="strDirName">虚拟目录名称</param>
/// <param name="strDirPath">虚拟目录路径</param>
/// <param name="siteEntry">要创建虚拟目录的原站点</param>
/// <returns></returns>
private bool CreateVirtualDirectory(string strDirName, string strDirPath, DirectoryEntry rootEntry)
{
try
{
DirectoryEntry childEntry = rootEntry.Children.Add(strDirName, "IIsWebVirtualDir");
childEntry.Invoke("AppCreate", true);
childEntry.Properties["Path"].Value = strDirPath;// @"D:\公司项目\盘县联网\SafetyProduce\SafetyNet\"; //文件夹路径
childEntry.Properties["AppFriendlyName"][0] = strDirName;//应用程序名称
childEntry.Properties["AccessRead"][0] = true; //读取权限
childEntry.Properties["AccessExecute"][0] = false; //执行(如ISAPI应用程序或CGI)
childEntry.Properties["AccessWrite"][0] = true; //写入
childEntry.Properties["AccessScript"][0] = true; //执行脚本(如ASP)
childEntry.Properties["EnableDirBrowsing"][0] = true; //浏览
childEntry.Properties["DefaultDoc"][0] = "UserLogin.aspx,Default.aspx"; ////设置默认文档,多值情况下中间用逗号分割
childEntry.CommitChanges(); rootEntry.CommitChanges(); return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString() "虚拟目录" strDirName "创建失败!"); return false;
}
}