2014-07-03 45 views
1

在過去的幾天中,我一直在閱讀這篇文章,並且似乎有很多關於如何創建Web安裝項目並使用自定義操作修改它的信息。到目前爲止,這種使用以下鏈接:如何修改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

然而,似乎沒有太大的如何具體修改用戶界面,使用戶可以創建一個新的網站,而不是從下拉列表中選擇在「安裝地址」操作中(在「開始」下)提供。除此之外,我還遇到過有關如何創建新應用程序池的代碼,但不知道如何阻止UI讓用戶選擇從列表中首先選擇1。

此刻我的安裝程序看起來很喜歡這樣的:

UI - Installation Address step

正如你可以看到該用戶目前有3場;網站,虛擬目錄和應用程序池。網站和應用程序池是其中包含現有選項的列表。在網站下拉列表的情況下,我真的希望這是一個文本框,允許用戶輸入他們希望創建的網站的名稱。對於應用程序池,我希望它完全消失,因爲我的自定義操作會自動創建應用程序池併爲其分配虛擬目錄(希望)。

我已經有了用於創建應用程序池,虛擬目錄並將其分配給應用程序池的代碼(尚未測試),但我無法看到如何編輯用戶界面以滿足我的需求。我是否需要刪除「安裝地址」步驟並創建我自己的定製?

下面

代碼的應用程序池的創建,虛擬目錄創建和虛擬目錄分配到應用程序池:

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

回答

1

我發現我可以刪除用戶界面中的「安裝地址」,並自定義一個帶有文本框。這似乎有點限制,但我能做到的唯一方法。

+0

我創建了一個Web安裝程序,以便將我的網站部署到IIS,但奇怪的是站點下拉和應用程序池下拉不顯示在安裝程序中。他們是否默認存在,或者我們需要爲安裝嚮導上顯示的這些下拉菜單做些特別的事情? – user2913184

+0

@ user2913184如果他們不在那裏,你將不得不創建一個自定義的。 – sr28

+0

事實上,這幾乎是我的想法,儘管感謝您的幫助。 – user2913184

相關問題