由於Apache2項目中的mod_aspdotnet sub-project實現上的問題(也可以說是bug吧),使我們在其上運行ASP.NET程式時,和在IIS上的aspnet_wp|w3wp中啟動並執行正確性上有一些差別,所以在Apache(mod_aspdotnet)上調試ASP.NET項目的原始碼就很有必要。雖然ASP.NET 2.0已經正式release,不過1.1版本的項目還是目前的主流,所以我們分別看看Apache對這兩個版本Framework的支援。正如我前面所說,ASP.NET 1.1的項目緊密地依賴IIS,所以目前我只能在Apache上調試已有的ASP.NET 1.1項目,而不能建立(原因後面再說)。由於IIS先安裝並佔用了80連接埠,所以我的Apache Web Server就只能運行在其它連接埠上了(如:8080,通過httpd.conf檔案配置)。
首先,我們需要讓這個被調試的項目在IIS上運行正確,並且項目可以被VS.NET 2003 IDE正確開啟。然後配置Apache,讓這個項目同時在Apache上也運行正確。我們就可以通過IDE的Ctrl+Alt+P來Attach希望被debug的進程,這時我們會看到在工作清單(需要check "Show system processes")裡居然有兩個Apache.exe進程。這裡我也不知道應該是哪個,雖然它們的類型都是".NET, Win32",不過只有一個是mod_aspdotnet的宿主進程。當然我們還是可以用個小trick來判斷,就是開啟taskmgr並重新整理Apache上啟動並執行Web網站的頁面,看那個Apache.exe進程佔用CPU,那麼它就是asp.net支援模組的宿主。Attach成功後就可以在VS.NET裡面設定斷點,進行step into/out的原始碼級調試了。
上面是對ASP.NET 1.1項目的調試方法,如果是ASP.NET 2.0的項目呢?由於.NET Framework及Visual Studio 2005的改進,調試2.0的ASP.NET項目變得奇easy! 只需要把項目在Apache上運行好後,用Visual Studio 2005開啟希望調試的頁面的原始碼(*.cs)檔案,Attach上Apache的進程後直接設定斷點就可以了,根本不需要開啟項目,當然也就和IIS完全脫離關係了。
// 不管是1.1還是2.0,都需要確定到底是哪個Apache.exe進程是宿主
在Apache上調試失敗的已知可能問題:
1、沒有使用debug版的項目dll來運行,這個...還是問題嗎?
2、第二種情況,如果不注意,可能會認為是Apache不能調試1.1的Asp.net。就是如果機器上同時裝了Fx1.1和Fx2.0,mod_aspdotnet會預設把我們的ASP.NET程式載入在Fx2.0上運行,這時如果用VS.NET 2003去調試將無法Attach任何Apache.exe進程。當然用Visual Studio 2005是可以的。解決辦法需要在httpd.conf中使用"AspNetVersion v1.1.4322"命令顯示指定Asp.net程式運行時的.NET Framework版本。
Created ASP.NET Project by VS.NET 2003 Command#region Created ASP.NET Project by VS.NET 2003 Command
GET localhost/DebugDemo/get_aspx_ver.aspx
500 Internal Server Error
GET localhost/get_aspx_ver.aspx
404 Not Found
GET localhost/DebugDemo/vs28758389629759149_tmp.htm
200 OK
POST localhost/DebugDemo/_vti_bin/_vti_aut/author.dll
100 Continue
401 Access denied
POST localhost/DebugDemo/_vti_bin/_vti_aut/author.dll
401 Access Denied
POST localhost/DebugDemo/_vti_bin/_vti_aut/author.dll
100 Continue
200 OK
POST localhost/_vti_bin/_vti_aut/author.dll
100 Continue
401 Access denied
POST localhost/_vti_bin/_vti_aut/author.dll
401 Access Denied
POST localhost/_vti_bin/_vti_aut/author.dll
100 Continue
200 OK
POST localhost/_vti_bin/_vti_adm/admin.dll
100 Continue
401 Access denied
POST localhost/_vti_bin/_vti_adm/admin.dll
401 Access Denied
POST localhost/_vti_bin/_vti_adm/admin.dll
100 Continue
200 OK
POST localhost/DebugDemo/_vti_bin/_vti_aut/author.dll
401 Access Denied
POST localhost/DebugDemo/_vti_bin/_vti_aut/author.dll
100 Continue
200 OK
POST localhost/DebugDemo/_vti_bin/_vti_aut/author.dll
#endregion
同樣在ASP.NET 2.0中,這個步驟完全不需要了,ASP.NET項目就是一個目錄,完全的和Web Server脫離開了。我們也就再也不用因為IIS的搗亂,而使的不能開發ASP.NET程式了~~~