本文介绍了IIS Web部署 - 创建虚拟目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上VS2010开发一个网站/ IIS 7.5,我使用的Web部署,从我的机器网站发布到开发站点服务器。

When developing a site on VS2010/IIS 7.5, I'm using Web Deploy to publish the site from my machine to the dev site server.

该网站有大约40虚拟目录,我想在部署过程中,自动将创建这些服务器上。有一个简单的方法来做到这一点?

The site has about 40 virtual directories, and I'd like to automagically create those on the server during the deployment. Is there a simple way to do this?

我考虑写一个小的应用程序,将来自文件或数据库加载列表,并根据需要创建它们。该目录具有比Web服务器上我的开发机上不同的物理路径,另外,它抛出一个扳手到作品中。

I'm considering writing a small app that would load the list from a file or database and create them on demand. The directories have different physical paths on my development machine than on the web server, also, which throws a wrench into the works.

推荐答案

如果你使用的MSBuild为您的网络部署可以在.NET中,您可以用它来创建虚拟目录写CustomBuildTask。

If you're using MSBuild for your web deploy you can write a CustomBuildTask in .net that you can use to create your virtual directory.

有关于如何创建和使用一个自定义生成的任务,但这里有很多的资源是code我用使用自定义生成任务来创建一个虚拟目录:

There are a lot of resources on how to create and consume a custom build task, but here is the code I use to create a virtual directory using a custom build task:

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();
}

这篇关于IIS Web部署 - 创建虚拟目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-19 04:33
查看更多