在 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();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)