VS2005 ASP.NET2.0安装项目的制作(包括数据库创建、站点创建、IIS属性修改、Web.Config文件修改)
2、創(chuàng)建新的安項(xiàng)目之后,在(文件系統(tǒng)編輯器)里的應(yīng)用程序文件夾里,添加ASP.net2.0的項(xiàng)目輸出(還有第二種方法是用ASP.NET2.0發(fā)布網(wǎng)站到一個(gè)文件夾下面,再把這個(gè)文件夾下面所有文件復(fù)制粘貼過來,這樣生成的安裝文件,在安裝之后就沒有源代碼文件了,我自己就是這樣做的)如下圖:
圖1下圖的MyPojectSetup項(xiàng)目下已有了Web項(xiàng)目的輸出,以及一個(gè)SQL腳本(SQL腳本是通SQL2005生成的,將在安裝類庫里要使用的)
圖2文件系統(tǒng)左邊界面,添加了Web項(xiàng)目輸出
2.2添加完項(xiàng)目輸出之后,需要設(shè)置安裝界面。我們的要求是第一、建一個(gè)新站點(diǎn),所以需要所安裝的IIS服務(wù)器地址,以及新站點(diǎn)的端口。第二、需要數(shù)據(jù)庫的地址,新建的數(shù)據(jù)庫名稱,以及訪問數(shù)據(jù)庫的用戶名和密碼兩項(xiàng)(需要有創(chuàng)庫權(quán)限的)。
如圖1在文件系統(tǒng)編輯器右邊,選擇用戶界面,然后看到如下:
在啟動(dòng)選擇單擊右擊菜單,添加對(duì)話框A,并在對(duì)話框A上單擊右鍵=》上移到安裝文件夾的上面:
再次設(shè)置右邊屬性,文本框A是站點(diǎn)信息輸入如下信息,其中Edit1Property是一個(gè)需要傳入安裝類的參數(shù)。
按照以上方式再添加文本框B并移到文本框A的下面,如下圖所示
注意:如上所示安裝項(xiàng)目基本的事情已經(jīng)做完了,但還有最后一個(gè)步驟沒有做,那就是自定義操作,也就安裝的重中之重的事情,安裝類庫的創(chuàng)建,如3點(diǎn)所示。創(chuàng)建安裝類庫之后就需要把它的輸出來添加到安裝項(xiàng)目里如同Web項(xiàng)目,然后設(shè)置自定義活動(dòng)為這個(gè)項(xiàng)目就可以,詳情在下面介紹。
3、需要?jiǎng)?chuàng)建一個(gè)安裝類庫,里面把Class1.cs刪除,再添加一個(gè)新的安裝文件。安裝項(xiàng)目所有的自定義都是在這里用編碼完成的(包括數(shù)據(jù)庫生成,虛擬站點(diǎn)創(chuàng)建,IIS屬性修改,Web.Config文件修改)。也就是說,安裝項(xiàng)目是個(gè)外殼,通過創(chuàng)建一些界面接收用戶參數(shù),然后利用這個(gè)安裝類庫,提供的功能,進(jìn)行自己的操作。
?
4、安裝程序類新建之后,雙擊進(jìn)入代碼狀態(tài),用override重載Install函數(shù)如下所示:
?
using?System;using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Configuration.Install;
namespace?MyProjectInstall
...{
????[RunInstaller(true)]
????public?partial?class?InstallerMySample?:?Installer
????...{
????????public?InstallerMySample()
????????...{
????????????InitializeComponent();
????????}
????????public?override?void?Install(System.Collections.IDictionary?stateSaver)
????????...{
????????}
????}
}
?
安裝數(shù)據(jù)庫的代碼如下,其中用了兩種方法,一種是用SQL命令方式創(chuàng)建數(shù)據(jù)庫,另一種是調(diào)用osql命令執(zhí)行腳本,創(chuàng)建數(shù)據(jù)表結(jié)構(gòu)等,最后用命令追加一條記錄.
?
?????數(shù)據(jù)庫操作#region?數(shù)據(jù)庫操作????????protected?void?AddDBTable()
????????...{
????????????try
????????????...{
????????????????//創(chuàng)建數(shù)據(jù)庫
????????????????ExcuteSQL("master",?string.Format("CREATE?DATABASE?{0}",?this._dataBaseName));
????????????????//調(diào)用osql執(zhí)行腳本
????????????????ExcuteScript();
????????????????//添加原始數(shù)據(jù)
????????????????ExcuteSQL(_dataBaseName,?"INSERT?INTO?GV_SystemAdmin(SystemAdminUser,SystemAdminPass,SystemAdminName,SystemAdminMemo)?VALUES?('admin',?'admin',?'Administrator'?,'系統(tǒng)默認(rèn)超級(jí)用戶')");
????????????}
????????????catch?(Exception?ex)
????????????...{
????????????????throw?new?ApplicationException(ex.Message);
????????????}
????????}
????????//此方法在本例中未用到,因?yàn)樽詈笾灰芳右粭l記錄,
????????//但如果有多條可以寫成一個(gè)腳本,以資源的形式嵌入到這個(gè)項(xiàng)目
????????//然后用如下的方法讀取,然后調(diào)用SQL命令執(zhí)行
????????private?string?GetSQLScript(string?fileName)
????????...{
????????????try
????????????...{
????????????????//得到當(dāng)前程序集
????????????????Assembly?asm?=?Assembly.GetExecutingAssembly();
????????????????//資源文件
????????????????Stream?strm?=
????????????????????asm.GetManifestResourceStream(asm.GetName().Name?+?"."?+?fileName);
????????????????//讀取嵌入文件內(nèi)容,文本文件內(nèi)容必須為Unicode
????????????????StreamReader?reader?=?new?StreamReader(strm);
????????????????return?reader.ReadToEnd();
????????????}
????????????catch
????????????...{
????????????????return?String.Empty;
????????????}
????????}
????????private?void?ExcuteSQL(string?dataBaseName,?string?SQL)
????????...{
????????????SqlConnection?con?=
????????????????new?SqlConnection(string.Format("user?id={0};password={1};Initial?Catalog={2};Data?Source={3};",?_username,?_saPassword,?dataBaseName,?_servername));
????????????SqlCommand?cmd?=?new?SqlCommand(SQL,?con);
????????????cmd.Connection.Open();
????????????cmd.Connection.ChangeDatabase(dataBaseName);
????????????try
????????????...{
????????????????cmd.ExecuteNonQuery();
????????????}
????????????finally
????????????...{
????????????????//最后總要關(guān)閉數(shù)據(jù)庫
????????????????cmd.Connection.Close();
????????????}
????????}?????
????????private?void?ExcuteScript()
????????...{
????????????try
????????????...{
????????????????Process?sqlProcess?=?new?Process();
????????????????//調(diào)用osql必須在目標(biāo)機(jī),也就是安裝的機(jī)子上要有安裝SQLServer服務(wù)器
????????????????//不然找不到這個(gè)命令
????????????????sqlProcess.StartInfo.FileName?=?"osql.exe";
????????????????//如下所指的SQL腳本文件是打包打安裝項(xiàng)目的文件名,
????????????????//targetPath就是在安裝界面用戶指定的安裝目錄
????????????????sqlProcess.StartInfo.Arguments?=?string.Format("-U?{0}?-P{1}?-d?{2}?-S?{3}?-i?{4}VideoMeetingCreateSQL2000.sql",
????????????????????_username,?_saPassword,?_dataBaseName,?_servername,?_targetPath);
????????????????sqlProcess.StartInfo.WindowStyle?=?ProcessWindowStyle.Hidden;
????????????????sqlProcess.Start();
????????????????sqlProcess.WaitForExit();
????????????????sqlProcess.Close();
????????????}
????????????catch?(Exception?ex)
????????????...{
????????????????throw?ex;
????????????}
????????}
????????#endregion
?修改Web.Config配置的代碼如下:
?WriteWebConfig?修改web.config的連接數(shù)據(jù)庫的字符串#region?WriteWebConfig?修改web.config的連接數(shù)據(jù)庫的字符串????????private?bool?WriteWebConfig()
????????...{
????????????System.IO.FileInfo?FileInfo?=?new?System.IO.FileInfo(this.Context.Parameters["targetdir"]?+?"/web.config");
????????????if?(!FileInfo.Exists)
????????????...{
????????????????throw?new?InstallException("Missing?config?file?:"?+?this.Context.Parameters["targetdir"]?+?"/web.config");
????????????}
????????????System.Xml.XmlDocument?xmlDocument?=?new?System.Xml.XmlDocument();
????????????xmlDocument.Load(FileInfo.FullName);
????????????bool?FoundIt?=?false;
????????????foreach?(System.Xml.XmlNode?Node?in?xmlDocument["configuration"]["connectionStrings"])
????????????...{
????????????????if?(Node.Name?==?"add")
????????????????...{
????????????????????if?(Node.Attributes.GetNamedItem("name").Value?==?"MonitorConnectionString")
????????????????????...{
????????????????????????Node.Attributes.GetNamedItem("connectionString").Value?=?String.Format("Data?Source={0};database={1};User?ID={2};Password={3}",?_servername,?_dataBaseName,?_username,?_saPassword);
????????????????????????FoundIt?=?true;
????????????????????}
????????????????}
????????????}
????????????if?(!FoundIt)
????????????...{
????????????????throw?new?InstallException("Error?when?writing?the?config?file:?web.config");
????????????}
????????????xmlDocument.Save(FileInfo.FullName);
????????????return?FoundIt;
????????}
????????#endregion
創(chuàng)建IIS站點(diǎn)的代碼如下(注我也是從網(wǎng)找到的,其中CreateNewWebsit這個(gè)方法中我加了IIS參數(shù)設(shè)置的代碼,也就是在創(chuàng)建IIS時(shí)一并設(shè)置了):
注意這一句:string fileName = Environment.GetEnvironmentVariable("windir") + @"/Microsoft.NET/Framework/v2.0.50727/ASPnet_regiis.exe";原因是當(dāng)你不管是手動(dòng)還是自動(dòng)創(chuàng)建一個(gè)新站點(diǎn),在它的屬性頁ASP.NET設(shè)置里都會(huì)有1.1版和2.0版這個(gè)選項(xiàng),默認(rèn)是1.1,現(xiàn)在我要部署2.0所以在默認(rèn)情況下就不能夠一步到位,安裝完就可以訪問執(zhí)行,而要去設(shè)置成2.0才行.所以要調(diào)用FrameworkV2.0下的regiis.exe得新注冊(cè)一下我們指定的虛擬目錄,使它是2.0.?
using?System;using?System.DirectoryServices;
using?System.Collections;
using?System.Text.RegularExpressions;
using?System.Text;
using?System.Runtime;
using?System.Diagnostics;
/**//**
?*?@author?吳海燕
?*?@email??wuhy80-usual@yahoo.com
?*?2004-6-25?第一版
?*/
namespace?Wuhy.ToolBox
...{
????/**////?<summary>
????///??這個(gè)類是靜態(tài)類。用來實(shí)現(xiàn)管理IIS的基本操作。
????///??管理IIS有兩種方式,一是ADSI,一是WMI。由于系統(tǒng)限制的原因,只好選擇使用ADSI實(shí)現(xiàn)功能。
????///??這是一個(gè)遺憾。只有等到只有使用IIS?6的時(shí)候,才有可能使用WMI來管理系統(tǒng)
????///??不過有一個(gè)問題就是,我現(xiàn)在也覺得這樣的一個(gè)方法在本地執(zhí)行會(huì)比較的好。最好不要遠(yuǎn)程執(zhí)行。
????///??因?yàn)槟菢有枰加孟喈?dāng)數(shù)量的帶寬,即使要遠(yuǎn)程執(zhí)行,也是推薦在同一個(gè)網(wǎng)段里面執(zhí)行
????///?</summary>
????public?class?IISAdminLib
????...{
????????UserName,Password,HostName的定義#region?UserName,Password,HostName的定義
????????public?static?string?HostName
????????...{
????????????get
????????????...{
????????????????return?hostName;
????????????}
????????????set
????????????...{
????????????????hostName?=?value;
????????????}
????????}
????????public?static?string?UserName
????????...{
????????????get
????????????...{
????????????????return?userName;
????????????}
????????????set
????????????...{
????????????????userName?=?value;
????????????}
????????}
????????public?static?string?Password
????????...{
????????????get
????????????...{
????????????????return?password;
????????????}
????????????set
????????????...{
????????????????if?(UserName.Length?<=?1)
????????????????...{
????????????????????throw?new?ArgumentException("還沒有指定好用戶名。請(qǐng)先指定用戶名");
????????????????}
????????????????password?=?value;
????????????}
????????}
????????public?static?void?RemoteConfig(string?hostName,?string?userName,?string?password)
????????...{
????????????HostName?=?hostName;
????????????UserName?=?userName;
????????????Password?=?password;
????????}
????????private?static?string?hostName?=?"localhost";
????????private?static?string?userName;
????????private?static?string?password;
????????#endregion
????????根據(jù)路徑構(gòu)造Entry的方法#region?根據(jù)路徑構(gòu)造Entry的方法
????????/**////?<summary>
????????///??根據(jù)是否有用戶名來判斷是否是遠(yuǎn)程服務(wù)器。
????????///??然后再構(gòu)造出不同的DirectoryEntry出來
????????///?</summary>
????????///?<param?name="entPath">DirectoryEntry的路徑</param>
????????///?<returns>返回的是DirectoryEntry實(shí)例</returns>
????????public?static?DirectoryEntry?GetDirectoryEntry(string?entPath)
????????...{
????????????DirectoryEntry?ent;
????????????if?(UserName?==?null)
????????????...{
????????????????ent?=?new?DirectoryEntry(entPath);
????????????}
????????????else
????????????...{
????????????????//????ent?=?new?DirectoryEntry(entPath,?HostName+"/"+UserName,?Password,?AuthenticationTypes.Secure);
????????????????ent?=?new?DirectoryEntry(entPath,?UserName,?Password,?AuthenticationTypes.Secure);
????????????}
????????????return?ent;
????????}
????????#endregion
????????添加,刪除網(wǎng)站的方法#region?添加,刪除網(wǎng)站的方法
????????/**////?<summary>
????????///??創(chuàng)建一個(gè)新的網(wǎng)站。根據(jù)傳過來的信息進(jìn)行配置
????????///?</summary>
????????///?<param?name="siteInfo">存儲(chǔ)的是新網(wǎng)站的信息</param>
????????public?static?void?CreateNewWebSite(NewWebSiteInfo?siteInfo)
????????...{
????????????if?(!EnsureNewSiteEnavaible(siteInfo.BindString))
????????????...{
????????????????throw?new?Exception("已經(jīng)有了這樣的網(wǎng)站了。"?+?Environment.NewLine?+?siteInfo.BindString);
????????????}
????????????string?entPath?=?String.Format("IIS://{0}/w3svc",?HostName);
????????????DirectoryEntry?rootEntry?=?GetDirectoryEntry(entPath);
????????????string?newSiteNum?=?GetNewWebSiteID();
????????????DirectoryEntry?newSiteEntry?=?rootEntry.Children.Add(newSiteNum,?"IIsWebServer");
????????????newSiteEntry.CommitChanges();
????????????//Hashtable?ahs1?=?new?Hashtable();
????????????//foreach?(string?a1?in?newSiteEntry.Properties.PropertyNames)
????????????//{
????????????//????ahs1.Add(a1,?newSiteEntry.Properties[a1].Value);
????????????//}
????????????newSiteEntry.Properties["ServerBindings"].Value?=?siteInfo.BindString;
????????????newSiteEntry.Properties["ServerComment"].Value?=?siteInfo.CommentOfWebSite;
????????????newSiteEntry.CommitChanges();
????????????DirectoryEntry?vdEntry?=?newSiteEntry.Children.Add("root",?"IIsWebVirtualDir");
????????????vdEntry.CommitChanges();
????????????vdEntry.Properties["Path"].Value?=?siteInfo.WebPath;
????????????vdEntry.Invoke("AppCreate",?true);//創(chuàng)建應(yīng)用程序
????????????vdEntry.Properties["AccessRead"][0]?=?true;?//設(shè)置讀取權(quán)限
????????????vdEntry.Properties["DefaultDoc"][0]?=?"default.htm";//設(shè)置默認(rèn)文檔
????????????vdEntry.Properties["AppFriendlyName"][0]?=?"VideoMeeting";?//應(yīng)用程序名稱
????????????vdEntry.Properties["AccessScript"][0]?=?true;//執(zhí)行權(quán)限
????????????vdEntry.Properties["AuthFlags"][0]?=?1;//0表示不允許匿名訪問,1表示就可以3為基本身份驗(yàn)證,7為windows繼承身份驗(yàn)證
????????????//Hashtable?ahs?=?new?Hashtable();
????????????//ArrayList?list?=?new?ArrayList();
????????????//foreach?(string?a?in?vdEntry.Properties.PropertyNames)
????????????//{
????????????//????list.Add(a);
????????????//????ahs.Add(a,?vdEntry.Properties[a].Value);
????????????//}
????????????vdEntry.CommitChanges();
???????????
????????????//啟動(dòng)ASPnet_iis.exe程序?
????????????string?fileName?=?Environment.GetEnvironmentVariable("windir")?+?@"Microsoft.NETFrameworkv2.0.50727ASPnet_regiis.exe";
????????????ProcessStartInfo?startInfo?=?new?ProcessStartInfo(fileName);
????????????//處理目錄路徑?
????????????string?path?=?vdEntry.Path.ToUpper();
????????????int?index?=?path.IndexOf("W3SVC");
????????????path?=?path.Remove(0,?index);
????????????//啟動(dòng)ASPnet_iis.exe程序,刷新教本映射?
????????????startInfo.Arguments?=?"-s?"?+?path;
????????????startInfo.WindowStyle?=?ProcessWindowStyle.Hidden;
????????????startInfo.UseShellExecute?=?false;
????????????startInfo.CreateNoWindow?=?true;
????????????startInfo.RedirectStandardOutput?=?true;
????????????startInfo.RedirectStandardError?=?true;
????????????Process?process?=?new?Process();
????????????process.StartInfo?=?startInfo;
????????????process.Start();
????????????process.WaitForExit();
????????????string?errors?=?process.StandardError.ReadToEnd();
????????????if?(errors?!=?string.Empty)
????????????...{
????????????????throw?new?Exception(errors);
????????????}
????????}
????????/**////?<summary>
????????///??刪除一個(gè)網(wǎng)站。根據(jù)網(wǎng)站名稱刪除。
????????///?</summary>
????????///?<param?name="siteName">網(wǎng)站名稱</param>
????????public?static?void?DeleteWebSiteByName(string?siteName)
????????...{
????????????string?siteNum?=?GetWebSiteNum(siteName);
????????????string?siteEntPath?=?String.Format("IIS://{0}/w3svc/{1}",?HostName,?siteNum);
????????????DirectoryEntry?siteEntry?=?GetDirectoryEntry(siteEntPath);
????????????string?rootPath?=?String.Format("IIS://{0}/w3svc",?HostName);
????????????DirectoryEntry?rootEntry?=?GetDirectoryEntry(rootPath);
????????????rootEntry.Children.Remove(siteEntry);
????????????rootEntry.CommitChanges();
????????}
????????#endregion
????????Start和Stop網(wǎng)站的方法#region?Start和Stop網(wǎng)站的方法
????????public?static?void?StartWebSite(string?siteName)
????????...{
????????????string?siteNum?=?GetWebSiteNum(siteName);
????????????string?siteEntPath?=?String.Format("IIS://{0}/w3svc/{1}",?HostName,?siteNum);
????????????DirectoryEntry?siteEntry?=?GetDirectoryEntry(siteEntPath);
????????????siteEntry.Invoke("Start",?new?object[]?...{?});
????????}
????????
????????public?static?void?StopWebSite(string?siteName)
????????...{
????????????string?siteNum?=?GetWebSiteNum(siteName);
????????????string?siteEntPath?=?String.Format("IIS://{0}/w3svc/{1}",?HostName,?siteNum);
????????????DirectoryEntry?siteEntry?=?GetDirectoryEntry(siteEntPath);
????????????siteEntry.Invoke("Stop",?new?object[]?...{?});
????????}
????????#endregion
????????
????????確認(rèn)網(wǎng)站是否相同#region?確認(rèn)網(wǎng)站是否相同
????????/**////?<summary>
????????///??確定一個(gè)新的網(wǎng)站與現(xiàn)有的網(wǎng)站沒有相同的。
????????///??這樣防止將非法的數(shù)據(jù)存放到IIS里面去
????????///?</summary>
????????///?<param?name="bindStr">網(wǎng)站邦定信息</param>
????????///?<returns>真為可以創(chuàng)建,假為不可以創(chuàng)建</returns>
????????public?static?bool?EnsureNewSiteEnavaible(string?bindStr)
????????...{
????????????string?entPath?=?String.Format("IIS://{0}/w3svc",?HostName);
????????????DirectoryEntry?ent?=?GetDirectoryEntry(entPath);
????????????foreach?(DirectoryEntry?child?in?ent.Children)
????????????...{
????????????????if?(child.SchemaClassName?==?"IIsWebServer")
????????????????...{
????????????????????if?(child.Properties["ServerBindings"].Value?!=?null)
????????????????????...{
????????????????????????if?(child.Properties["ServerBindings"].Value.ToString()?==?bindStr)
????????????????????????...{
????????????????????????????return?false;
????????????????????????}
????????????????????}
????????????????}
????????????}
????????????return?true;
????????}
????????#endregion
????????獲取一個(gè)網(wǎng)站編號(hào)的方法#region?獲取一個(gè)網(wǎng)站編號(hào)的方法
????????/**////?<summary>
????????///??獲取一個(gè)網(wǎng)站的編號(hào)。根據(jù)網(wǎng)站的ServerBindings或者ServerComment來確定網(wǎng)站編號(hào)
????????///?</summary>
????????///?<param?name="siteName"></param>
????????///?<returns>返回網(wǎng)站的編號(hào)</returns>
????????///?<exception?cref="NotFoundWebSiteException">表示沒有找到網(wǎng)站</exception>
????????public?static?string?GetWebSiteNum(string?siteName)
????????...{
????????????Regex?regex?=?new?Regex(siteName);
????????????string?tmpStr;
????????????string?entPath?=?String.Format("IIS://{0}/w3svc",?HostName);
????????????DirectoryEntry?ent?=?GetDirectoryEntry(entPath);
????????????foreach?(DirectoryEntry?child?in?ent.Children)
????????????...{
????????????????if?(child.SchemaClassName?==?"IIsWebServer")
????????????????...{
????????????????????if?(child.Properties["ServerBindings"].Value?!=?null)
????????????????????...{
????????????????????????tmpStr?=?child.Properties["ServerBindings"].Value.ToString();
????????????????????????if?(regex.Match(tmpStr).Success)
????????????????????????...{
????????????????????????????return?child.Name;
????????????????????????}
????????????????????}
????????????????????if?(child.Properties["ServerComment"].Value?!=?null)
????????????????????...{
????????????????????????tmpStr?=?child.Properties["ServerComment"].Value.ToString();
????????????????????????if?(regex.Match(tmpStr).Success)
????????????????????????...{
????????????????????????????return?child.Name;
????????????????????????}
????????????????????}
????????????????}
????????????}
????????????throw?new?Exception("沒有找到我們想要的站點(diǎn)"?+?siteName);
????????}
????????#endregion????????
????????獲取新網(wǎng)站id的方法#region?獲取新網(wǎng)站id的方法
????????/**////?<summary>
????????///??獲取網(wǎng)站系統(tǒng)里面可以使用的最小的ID。
????????///??這是因?yàn)槊總€(gè)網(wǎng)站都需要有一個(gè)唯一的編號(hào),而且這個(gè)編號(hào)越小越好。
????????///??這里面的算法經(jīng)過了測試是沒有問題的。
????????///?</summary>
????????///?<returns>最小的id</returns>
????????public?static?string?GetNewWebSiteID()
????????...{
????????????ArrayList?list?=?new?ArrayList();
????????????string?tmpStr;
????????????string?entPath?=?String.Format("IIS://{0}/w3svc",?HostName);
????????????DirectoryEntry?ent?=?GetDirectoryEntry(entPath);
????????????foreach?(DirectoryEntry?child?in?ent.Children)
????????????...{
????????????????if?(child.SchemaClassName?==?"IIsWebServer")
????????????????...{
????????????????????tmpStr?=?child.Name.ToString();
????????????????????list.Add(Convert.ToInt32(tmpStr));
????????????????}
????????????}
????????????list.Sort();
????????????int?i?=?1;
????????????foreach?(int?j?in?list)
????????????...{
????????????????if?(i?==?j)
????????????????...{
????????????????????i++;
????????????????}
????????????}
????????????return?i.ToString();
????????}
????????#endregion
????}
????
????新網(wǎng)站信息結(jié)構(gòu)體#region?新網(wǎng)站信息結(jié)構(gòu)體
????public?struct?NewWebSiteInfo
????...{
????????private?string?hostIP;???//?The?Hosts?IP?Address
????????private?string?portNum;???//?The?New?Web?Sites?Port.generally?is?"80"
????????private?string?descOfWebSite;?//?網(wǎng)站表示。一般為網(wǎng)站的網(wǎng)站名。例如"www.dns.com.cn"
????????private?string?commentOfWebSite;//?網(wǎng)站注釋。一般也為網(wǎng)站的網(wǎng)站名。
????????private?string?webPath;???//?網(wǎng)站的主目錄。例如"e: mp"
????????public?NewWebSiteInfo(string?hostIP,?string?portNum,?string?descOfWebSite,?string?commentOfWebSite,?string?webPath)
????????...{
????????????this.hostIP?=?hostIP;
????????????this.portNum?=?portNum;
????????????this.descOfWebSite?=?descOfWebSite;
????????????this.commentOfWebSite?=?commentOfWebSite;
????????????this.webPath?=?webPath;
????????}
????????public?string?BindString
????????...{
????????????get
????????????...{
????????????????return?String.Format("{0}:{1}:{2}",?hostIP,?portNum,?descOfWebSite);
????????????}
????????}
????????public?string?CommentOfWebSite
????????...{
????????????get
????????????...{
????????????????return?commentOfWebSite;
????????????}
????????}
????????public?string?WebPath
????????...{
????????????get
????????????...{
????????????????return?webPath;
????????????}
????????}
????}
????#endregion
}
?
最后重載的InStall函數(shù)如:
?
????public?override?void?Install(IDictionary?stateSaver)????????...{
????????????//數(shù)據(jù)庫安裝程序入口
????????????_saPassword?=?this.Context.Parameters["pwd"];
????????????_dataBaseName?=?this.Context.Parameters["dbname"];
????????????_targetPath?=?this.Context.Parameters["targetdir"];
????????????_servername?=?this.Context.Parameters["server"];
????????????_username?=?this.Context.Parameters["user"];
????????????iis?=?this.Context.Parameters["iis"];
????????????port?=?this.Context.Parameters["port"];
????????????//添加數(shù)據(jù)庫
????????????AddDBTable();
????????????//注冊(cè)新站點(diǎn)????????????
????????????Wuhy.ToolBox.NewWebSiteInfo?siteInfo?=?new?Wuhy.ToolBox.NewWebSiteInfo(string.Empty,?port,?"",?"VideoMeeting",?_targetPath);
????????????Wuhy.ToolBox.IISAdminLib.HostName?=?iis;
????????????Wuhy.ToolBox.IISAdminLib.UserName?=?null;???????
????????????Wuhy.ToolBox.IISAdminLib.CreateNewWebSite(siteInfo);
????????????Wuhy.ToolBox.IISAdminLib.StartWebSite(siteInfo.BindString);
????????????
????????????//修改Web.Config文件
????????????if?(!WriteWebConfig())
????????????...{
????????????????throw?new?ApplicationException("設(shè)置數(shù)據(jù)庫連接字符串時(shí)出現(xiàn)錯(cuò)誤");
????????????}
????????}
總結(jié)
以上是生活随笔為你收集整理的VS2005 ASP.NET2.0安装项目的制作(包括数据库创建、站点创建、IIS属性修改、Web.Config文件修改)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#生成安装文件后自动附加数据库的思路跟
- 下一篇: 实现TcpIp简单传送