博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
代码创建IIS站点
阅读量:4952 次
发布时间:2019-06-11

本文共 4422 字,大约阅读时间需要 14 分钟。

 #region 新建立一个IISWEB站点

        ///<summary>
       
///添加一个站点
       
///</summary>
        public string CreateWebSite()
        {
           
int siteID = int.Parse(GetNewWebSiteID());
           
try
            {
                root
= new DirectoryEntry("IIS://" + this._server + "/W3SVC");
               
if (EnsureNewSiteEnavaible(this._serverip + ":" + this._port + ":" + this._domain) || EnsureNewSiteEnavaible(this._server + ":" + this._port + ":" + this._domain))
                {
                   
return "该站点已经存在,请重新命名站点!";
                }
               
else
                {
                    DirectoryEntry site
= (DirectoryEntry)root.Invoke("Create", "IIsWebServer", siteID);
                    site.Invoke(
"Put", "ServerComment", this._webSiteName);
                    site.Invoke(
"Put", "KeyType", "IIsWebServer");
                    site.Invoke(
"Put", "ServerBindings", this._serverip + ":" + this._port + ":" + this._domain);
                    site.Invoke(
"Put", "ServerState", 2);
                    site.Invoke(
"Put", "FrontPageWeb", 1);
                    site.Invoke(
"Put", "DefaultDoc", "default.aspx,index.aspx,index.html,index.htm,default.htm,default.html");
                    site.Invoke(
"Put", "ServerAutoStart", 1);
                    site.Invoke(
"Put", "ServerSize", 1);
                    site.Invoke(
"SetInfo");
                    site.CommitChanges();
                    root.CommitChanges();
                    DirectoryEntry siteVDir
= site.Children.Add("Root", "IISWebVirtualDir");                 
                    siteVDir.Properties[
"AppIsolated"][0] = 2;
                    siteVDir.Properties[
"Path"][0] = this._path;
                    siteVDir.Properties[
"AccessFlags"][0] = 513;
                    siteVDir.Properties[
"FrontPageWeb"][0] = 1;
                    siteVDir.Properties[
"AppRoot"][0] = string.Format("/LM/W3SVC/{0}/Root", siteID);
                    siteVDir.Properties[
"AppFriendlyName"][0] = "默认应用程序";
                   
                 
                    PropertyValueCollection propValues
= siteVDir.Properties["MimeMap"];
                    IISOle.MimeMapClass newMimeType
= new IISOle.MimeMapClass();
                    newMimeType.Extension
= ".flv";
                    newMimeType.MimeType
= "flv-application/octet-stream";
                    propValues.Add(newMimeType);
                   
string strerror = @"400,*,FILE,C:\WINDOWS\help\iisHelp\common\400.htm" +
                       
@" 401,1,FILE,C:\WINDOWS\help\iisHelp\common\401-1.htm" +
                       
@" 401,2,FILE,C:\WINDOWS\help\iisHelp\common\401-2.htm" +
                       
@" 401,3,FILE,C:\WINDOWS\help\iisHelp\common\401-3.htm" +
                       
@" 401,4,FILE,C:\WINDOWS\help\iisHelp\common\401-4.htm" +
                       
@" 401,5,FILE,C:\WINDOWS\help\iisHelp\common\401-5.htm" +
                       
@" 401,7,FILE,C:\WINDOWS\help\iisHelp\common\401-1.htm" +
                       
@" 403,1,FILE,C:\WINDOWS\help\iisHelp\common\403-1.htm" +
                       
@" 403,2,FILE,C:\WINDOWS\help\iisHelp\common\403-2.htm" +
                       
@" 403,3,FILE,C:\WINDOWS\help\iisHelp\common\403-3.htm" +
                       
@" 403,4,FILE,C:\WINDOWS\help\iisHelp\common\403-4.htm" +
                       
@" 403,5,FILE,C:\WINDOWS\help\iisHelp\common\403-5.htm" +
                       
@" 403,6,FILE,C:\WINDOWS\help\iisHelp\common\403-6.htm" +
                       
@" 403,7,FILE,C:\WINDOWS\help\iisHelp\common\403-7.htm" +
                       
@" 403,8,FILE,C:\WINDOWS\help\iisHelp\common\403-8.htm" +
                       
@" 403,9,FILE,C:\WINDOWS\help\iisHelp\common\403-9.htm" +
                       
@" 403,10,FILE,C:\WINDOWS\help\iisHelp\common\403-10.htm" +
                       
@" 403,11,FILE,C:\WINDOWS\help\iisHelp\common\403-11.htm" +
                       
@" 403,12,FILE,C:\WINDOWS\help\iisHelp\common\403-12.htm" +
                       
@" 403,13,FILE,C:\WINDOWS\help\iisHelp\common\403-13.htm" +
                       
@" 403,15,FILE,C:\WINDOWS\help\iisHelp\common\403-15.htm" +
                       
@" 403,16,FILE,C:\WINDOWS\help\iisHelp\common\403-16.htm" +
                       
@" 403,17,FILE,C:\WINDOWS\help\iisHelp\common\403-17.htm" +
                       
@" 403,18,FILE,C:\WINDOWS\help\iisHelp\common\403.htm" +
                       
@" 403,19,FILE,C:\WINDOWS\help\iisHelp\common\403.htm" +
                       
@" 403,20,FILE,C:\WINDOWS\help\iisHelp\common\403-20.htm" +
                       
@" 404,*,URL,/404.aspx" +
                       
@" 404,2,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm" +
                       
@" 404,3,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm" +
                       
@" 405,*,FILE,C:\WINDOWS\help\iisHelp\common\405.htm" +
                       
@" 406,*,FILE,C:\WINDOWS\help\iisHelp\common\406.htm" +
                       
@" 407,*,FILE,C:\WINDOWS\help\iisHelp\common\407.htm" +
                       
@" 412,*,FILE,C:\WINDOWS\help\iisHelp\common\412.htm" +
                       
@" 414,*,FILE,C:\WINDOWS\help\iisHelp\common\414.htm" +
                       
@" 415,*,FILE,C:\WINDOWS\help\iisHelp\common\415.htm" +
                       
@" 500,12,FILE,C:\WINDOWS\help\iisHelp\common\500-12.htm" +
                       
@" 500,13,FILE,C:\WINDOWS\help\iisHelp\common\500-13.htm" +
                       
@" 500,15,FILE,C:\WINDOWS\help\iisHelp\common\500-15.htm" +
                       
@" 500,16,FILE,C:\WINDOWS\help\iisHelp\common\500.htm" +
                       
@" 500,17,FILE,C:\WINDOWS\help\iisHelp\common\500.htm" +
                       
@" 500,18,FILE,C:\WINDOWS\help\iisHelp\common\500.htm" +
                       
@" 500,19,FILE,C:\WINDOWS\help\iisHelp\common\500.htm";
                   
string[] strerrorlist = strerror.Split(' ');
                    siteVDir.Properties[
"HttpErrors"].Value = strerrorlist;
                    siteVDir.Invoke(
"AppCreate", true);
                    root.CommitChanges();
                    siteVDir.CommitChanges();
                    site.CommitChanges();
                   
return "创建站点成功!";
                }
            }
           
catch (Exception ex)
            {
               
return ex.Message;
            }
        }
       
#endregion

转载于:https://www.cnblogs.com/diony/archive/2011/05/20/2051853.html

你可能感兴趣的文章
初学差分约束
查看>>
HEVC编码学习(一)HM配置
查看>>
通过Spark SQL关联查询两个HDFS上的文件操作
查看>>
DataTable和 DataRow的 区别与联系
查看>>
检索COM 类工厂中CLSID 为 {00024500-0000-0000-C000-000000000046}的组件时失败
查看>>
mysql数据库中数据类型
查看>>
python-实现生产者消费者模型
查看>>
APP网络优化篇
查看>>
算法18-----判断是否存在符合条件的元素【list】
查看>>
《刑法》关于拐卖妇女儿童犯罪的规定
查看>>
Windows的本地时间(LocalTime)、系统时间(SystemTime)、格林威治时间(UTC-Time)、文件时间(FileTime)之间的转换...
查看>>
alias重启后失效了
查看>>
RestTemplate的Object与Entity的区别
查看>>
Fireworks基本使用
查看>>
《代码整洁之道》学习记录
查看>>
C++深入理解虚函数
查看>>
c#线程学习笔记一---基本概念
查看>>
2018-4-13
查看>>
两台电脑间的消息传输
查看>>
Linux 标准 I/O 库
查看>>