我經常用asp.net來寫一些小程式,寫起來友善,但是要部署到客戶的機器上,就成了麻煩事,客戶的機器上不一定有iis,并且使用者不一定願意安裝那個東西,
是以這裡我們要脫離iis執行asp.net,就用到這們這裡的cassini伺服器,
為了測試他的可用性,我先在iis下邊做一個示例工程:c:/inetpub/wwwroot/casi
裡邊包含了,一個讀取資料庫傳回dataset的webform,和一個讀取資料庫傳回dataset的service1.asmx
在iis上測試沒有問題,
接下來,測試cassini
首先從asp.net上下載下傳cassini的源代碼,裡邊有編譯好的exe程式,運作産生錯誤.
錯誤的内容:"cassini managed web server failed to start listening on port 8080.possible conflict with another web server on the same port"
發現這個錯誤後,我換了好幾個不可能被占用的端口,都是相同一的錯誤,我感到非常奇怪,
找一個非常簡單的端口掃描程式,檢測了一下端口,發現我測試的端口,都是沒有被占用的.
基于.net2.0 簡單端口測試程式.
<a href="http://dl2.csdn.net/down4/20070627/27113631782.exe">http://dl2.csdn.net/down4/20070627/27113631782.exe</a>
直到找這篇文章.
<a href="http://blog.csdn.net/shanhe/archive/2004/11/10/176422.aspx">http://blog.csdn.net/shanhe/archive/2004/11/10/176422.aspx</a>
裡邊詳細的說明的錯誤的原因,
我在這裡複制一一下:)
我将所有的源代碼拷貝到我的一個建立的工程裡邊,找到出錯的地方,
try {
_server = new cassini.server(portnumber, _virtroot, _apppath);
_server.start();
}
catch {
showerror(
"cassini managed web server failed to start listening on port " + portnumber + ". " +
"possible conflict with another web server on the same port.");
porttextbox.selectall();
porttextbox.focus();
return;
注釋掉try catch,找到源代碼,發現是server.cs檔案裡的createhost()這個函數
system.type _hosttype=typeof(host);
object o=applicationhost.createapplicationhost( _hosttype,_virtualpath, _physicalpath);
if(o ==null){throw new exception("不能建立application host object");}
_host =o as host;
if(_host ==null){
throw new exception("轉換失敗,請檢查黯轉換類型");
将函數代碼改成這樣,發現錯誤在:
object o=applicationhost.createapplicationhost( _hosttype,_virtualpath, _physicalpath);
經shanhe的專欄中的提示後,悄然大悟
将編譯成的cxycassini.exe拷貝到c:/inetpub/wwwroot/casi/bin下,運作 exe檔案,
寫好端口:8080
填上路徑,c:/inetpub/wwwroot/casi開始運作,
大功告成.呵呵