public int processrequest(intptr ecb, int iwrtype)
{
httpworkerrequest request1 = isapiworkerrequest.createworkerrequest(ecb, iwrtype);
string text1 = request1.getapppathtranslated();
string text2 = httpruntime.appdomainapppathinternal;
if (((text2 == null) || text1.equals(".")) ||
(string.compare(text1, text2, true, cultureinfo.invariantculture) == 0))
{
httpruntime.processrequest(request1);
return 0;
}
httpruntime.shutdownappdomain("physical application path changed from " +text2 + " to " + text1);
return 1;
}
這里實際的代碼并不重要, 記住這是從內部框架代碼中反編譯出來的, 你不能直接處理它, 它也有可能在將來發生改變.它只是用來揭示在幕后發生了什么.processrequest方法接收非托管的ecb引用并將它傳送給isapiworkerrequest對象, 此對象負責為當前請求創建創建請求上下文.在列表2中顯示了這個過程.
system.web.hosting.isapiworkerrequest類是httpworkerrequest類的一個抽象子類(譯注:httpworkerrequest和isapiworkerrequest都是抽象類, 并且isapiworkerrequest繼承自httpworkerrequest),它的工作是構建一個作為web應用輸入的輸入輸出的抽象視角。注意這里有另一個工廠方法:createworkerrequest, 通過判斷接受到的第二個參數來創建對應的workerrequest對象.有三個不同的版本:isapiworkerrequestinproc,isapiworkerrequestinprocforiis6, isapiworkerrequestoutofproc.每次有請求進入,這個對象被創建并作為請求和響應對象的基礎,它會接收它們的數據和由workerrequest提供的數據流.
抽象的httpworkerrequest類在低層接口上提供一個高層的抽象,這樣就封裝了數據是從哪里來的,可以是一個cgi web服務器,web瀏覽器控件或者是一些你用來給http運行時”喂”數據的自定義的機制.關鍵是asp.net能用統一的方法來接收信息。
在使用iis的情況下, 這個抽象是建立在isapi ecb塊周圍.在我們的請求處理過程中, isapiworkerrequest掛起isapi ecb并根據需要從它那里取出信息.列表2顯示了請求字符串值(query string value)是如何被取出來的.
列表2:使用非托管數據的isapiworkerrequest方法
// *** implemented in isapiworkerrequest
public override byte[] getquerystringrawbytes()
{
byte[] buffer1 = new byte[this._querystringlength];
if (this._querystringlength > 0)
{
int num1 = this.getquerystringrawbytescore(buffer1, this._querystringlength);
if (num1 != 1)
{
throw new httpexception( "cannot_get_query_string_bytes");
}
}
return buffer1;
}
// *** implemented in a specific implementation class isapiworkerrequestinprociis6
internal override int getquerystringcore(int encode,stringbuilder buffer, int size)
{
if (this._ecb == intptr.zero)
{
return 0;
}
return unsafenativemethods.ecbgetquerystring(this._ecb,encode,buffer,size);
}
isapiworkerrequest實現了一個高層次的包裝方法, 它調用了低層的核心方法, 負責真正的訪問非托管apis-或稱為”服務級別的實現”(service level implementation).這些核心方法在特殊的isapiworkerrequest子類中為它寄宿的環境提供特殊的實現, 這實現了簡單的擴展的(pluggable)環境, 這樣一來當以后新的web服務器接口或其他平臺成為了asp.net的目標時附加的實現類可以在被簡單的提供出來。這里還有一個協助類(helper class)system.web.unsafenativemethods.里面許多對isapi ecb結構的操作實現了對isapi擴展的非托管操作。,歡迎訪問網頁設計愛好者web開發。
新聞熱點
疑難解答
圖片精選