加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – IIS web部署 – 创建虚拟目录?

发布时间:2020-12-16 00:18:03 所属栏目:asp.Net 来源:网络整理
导读:在VS2010 / IIS 7.5上开发站点时,我正在使用Web Deploy将站点从我的机器发布到开发站点服务器. 该站点有大约40个虚拟目录,我想在部署期间自动在服务器上创建它们.有一个简单的方法吗? 我正在考虑编写一个小应用程序,它将从文件或数据库加载列表并按需创建它
在VS2010 / IIS 7.5上开发站点时,我正在使用Web Deploy将站点从我的机器发布到开发站点服务器.

该站点有大约40个虚拟目录,我想在部署期间自动在服务器上创建它们.有一个简单的方法吗?

我正在考虑编写一个小应用程序,它将从文件或数据库加载列表并按需创建它们.这些目录在我的开发机器上具有与在Web服务器上不同的物理路径,这也会引发工作.

解决方法

如果您使用MSBuild进行Web部署,则可以在.net中编写可用于创建虚拟目录的CustomBuildTask.

关于如何创建和使用自定义构建任务有很多资源,但这里是我使用自定义构建任务创建虚拟目录的代码:

public void CreateVirtualDirectory()
{

    DirectoryEntry oDE = new DirectoryEntry("IIS://" +
            this._strServerName + "/W3SVC/" + _webSiteID + "/Root");


    //Get Default Web Site
    DirectoryEntries oDC = oDE.Children;

    //Add row to schema
    DirectoryEntry oVirDir = oDC.Add(this._strVDirName,oDE.SchemaClassName.ToString());

    //Commit changes for Schema class File
    oVirDir.CommitChanges();


    //Set virtual directory to physical path
    oVirDir.Properties["Path"].Value = this._strPhysicalPath;

    //Set read access
    oVirDir.Properties["AccessRead"][0] = true;

    //Set the default docs
    oVirDir.Properties["EnableDefaultDoc"][0] = true;
    oVirDir.Properties["DefaultDoc"][0] = "default.aspx";

    //set the name
    oVirDir.Properties["AppFriendlyName"][0] = this._strVDirName;

    //do it
    oVirDir.Invoke("AppCreate",true);


    //set the application pool
    if (!string.IsNullOrEmpty(_strApplicationPool))
    {
        object[] param = { 0,_strApplicationPool,true };
        oVirDir.Invoke("AppCreate3",param);
        oVirDir.Properties["AppIsolated"][0] = "2";
    }

    //Save all the changes
    oVirDir.CommitChanges();
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读