简体   繁体   English

您如何修改Web设置项目以创建新的网站,应用程序池和虚拟目录?

[英]How do you modify a Web Setup Project to create a new website, app pool and virtual directory?

I've been reading up on this quite a lot over the last couple of days and there seems to be a lot of information out there on how to create a Web Setup Project and modify it with custom actions etc. I've got so far with this using the following links: 在过去的几天里,我一直在阅读很多有关此内容的信息,其中似乎有很多有关如何创建Web设置项目以及如何使用自定义操作对其进行修改的信息。使用以下链接:

http://weblogs.asp.net/scottgu/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005 http://msdn.microsoft.com/en-us/library/ms525598.aspx http://www.dreamincode.net/forums/topic/231074-setup-and-deployment-in-visual-studio-2010/ http://www.codeproject.com/Articles/146626/Extending-Visual-Studio-Setup-Project http://weblogs.asp.net/scottgu/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005 http://msdn.microsoft.com/zh-CN/library/ms525598 .aspx http://www.dreamincode.net/forums/topic/231074-setup-and-deployment-in-visual-studio-2010/ http://www.codeproject.com/Articles/146626/Extending-Visual-工作室-设置-项目

However, there doesn't seem to be much on how to specifically modify the User Interface so that the user can create a new site rather than select from the drop down list provided in the 'Installation Address' action (under 'Start'). 但是,关于如何专门修改用户界面,以便用户可以创建站点,而不是从“安装地址”操作(在“开始”下)提供的下拉列表中进行选择,似乎没有太多的选择。 In addition to that I've come across code in how to create a new application pool, but not how to stop the UI from giving the user the option of selecting 1 from the list first. 除此之外,我还遇到了有关如何创建新应用程序池的代码,但没有遇到如何阻止UI向用户提供从列表中首先选择1的选项的代码。

At the moment my installer looks likes this: 目前,我的安装程序如下所示:

UI-安装地址步骤

As you can see the user currently has 3 fields; 如您所见,用户当前有3个字段; Site, Virtual Directory and Application Pool. 站点,虚拟目录和应用程序池。 Site and Application Pool are lists with existing options in them. 站点和应用程序池是列表,其中包含现有选项。 In the case of the Site drop down list I actually want this to be a text box which allows the user to type in the name of the website they wish to create. 在“网站”下拉列表中,我实际上希望它是一个文本框,允许用户输入他们想要创建的网站的名称。 For Application Pool I want this to disappear completely as my Custom Action will automatically create an app pool and assign the virtual directory to it (hopefully). 对于“应用程序池”,我希望它完全消失,因为“自定义操作”将自动创建一个应用程序池,并将虚拟目录分配给它(希望如此)。

I already have the code (not tested yet) for creating the app pool, virtual directory and assigning it to the app pool but I can't see how to edit the UI for my needs. 我已经有了用于创建应用程序池,虚拟目录并将其分配给应用程序池的代码(尚未测试),但是我看不到如何根据需要编辑UI。 Do I need to delete the 'Installation Address' step and create my own custom one? 我是否需要删除“安装地址”步骤并创建自己的自定义步骤?

Code below for app pool creation, virtual directory creation and virtual directory assignment to app pool: 下面的代码用于创建应用程序池,创建虚拟目录以及向应用程序池分配虚拟目录:

//Properties for user input
private string targetSite { get { return this.Context.Parameters["targetsite"]; }}
private string targetVirtualDir { get { return this.Context.Parameters["targetvdir"]; } }
private string targetDirectory { get { return this.Context.Parameters["targetdir"]; } }
private const string ApplicationPool = "TestWebAppAP";
private const string BasePath = "IIS://Localhost/W3SVC/1/Root";
private const string AppPoolsAddress = "IIS://Localhost/W3SVC/AppPools";

//Install
public override void Install(System.Collections.IDictionary stateSaver)
{
    base.Install(stateSaver);

    if (targetSite == null) throw new InstallException("IIS site name not specified");
    else
    {
        CreateApplicationPool();
        CreateVirtualDir();
        AssignVDirtoAppPool();
    }
}

//Create Application Pool
private void CreateApplicationPool()
{
    try
    {
        DirectoryEntry NewPool;
        DirectoryEntry AppPools = new DirectoryEntry(AppPoolsAddress);
        NewPool = AppPools.Children.Add(ApplicationPool, "IIsApplicationPool");
        NewPool.CommitChanges();
    }
    catch (Exception ex)
    {
        MessageBox.Show("Failed to create new application pool \" " + ApplicationPool + "\". Error: " + ex.Message);
        throw new InstallException("Failed to create app pool", ex);
    }
}

//Create Virtual Directory
private void CreateVirtualDir()
{
    try
    {
        DirectoryEntry site = new DirectoryEntry(BasePath);
        string className = site.SchemaClassName.ToString();

        if (className.EndsWith("Server") || className.EndsWith("VirtualDir"))
        {
            DirectoryEntries vdirs = site.Children;
            DirectoryEntry newVDir = vdirs.Add(targetVirtualDir, (className.Replace("Service", "VirtualDir")));
            newVDir.Properties["Path"][0] = targetDirectory;
            newVDir.Properties["AccessScript"][0] = true;
            newVDir.Properties["AppFriendlyName"][0] = targetVirtualDir;
            newVDir.Properties["AppIsolated"][0] = "1";
            newVDir.Properties["AppRoot"][0] = "/LM" + BasePath.Substring(BasePath.IndexOf("/", ("IIS://".Length)));

            newVDir.CommitChanges();
        }
        else
        {
            MessageBox.Show("Failed to create virtual directory. It can only be created in a site or virtual directory node.");
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("Failed to create virtual directory \"" + targetVirtualDir + "\". Error: " + ex.Message);
        throw new InstallException("Failed to create virtual directory", ex);
    }
}

//Assign virtual directory to app pool
private void AssignVDirtoAppPool()
{
    try
    {
        DirectoryEntry vDir = new DirectoryEntry(BasePath);
        string className = vDir.SchemaClassName.ToString();

        if(className.EndsWith("VirtualDir"))
        {
            object[] param = { 0, ApplicationPool, true };
            vDir.Invoke("AppCreate3", param);
            vDir.Properties["AppIsolated"][0] = "2";
        }
        else
        {
            MessageBox.Show("Failed to assign to application pool. Only virtual directories can be assigned to application pools.");
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("Failed to assign virtual directory \"" + targetVirtualDir + "\" to application pool \"" + ApplicationPool + "\". Error: " + ex.Message);
        throw new InstallException("Failed to assign virtual directory to application pool", ex);
    }
}

I've found that I can just delete the 'Installation Address' in the UI and make a custom one with textboxes. 我发现我可以删除UI中的“安装地址”,并使用文本框进行自定义。 This seems a little restrictive but the only way I could do it. 这似乎有点限制性,但这是我可以做到的唯一方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Web 安装项目中创建新的应用程序池? - How can I create a new application pool in a Web Setup Project? 通过安装文件创建站点,虚拟目录和APP池 - Create Site,Virtual directory and APP pool by a setup file 如何为安装项目创建属性? - How do you Create Properties For Setup Project? 使用Web安装项目,如何在IIS中而不在默认站点中创建新网站? - Using a Web Setup Project how can I create a new website in IIS NOT in the Default Site? 如何在Visual Studio 2008 SP1中使用Web安装程序项目在IIS中创建新网站 - How to create new website in IIS using Web Setup Project in Visual Studio 2008 SP1 以编程方式为网站创建虚拟目录-Web应用程序 - create a virtual directory for a website programmatically- web application 向 web 应用程序添加通用内容虚拟目录时如何做安全权限? - How do you do security permissions when adding a common content virtual directory to a web application? 如何设置 ASP.Net 3.0 Core Web API 项目以使用 AutoFac 和 NLog? - How do you setup an ASP.Net 3.0 Core Web API project to use AutoFac and NLog? 如何新建项目并将其部署到现有站点的虚拟目录中? - how to new project and deploy it to a virtual directory of an existing site? 调试(单步执行)VS安装项目,你是如何做到的? - Debugging (Stepping through) a VS setup project, How do you do it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM