VISION:
後台使用c#編寫服務端(=codebehind)
前台使用js+ajax互動。
取消viewstate功能。
handler本質上是無狀態的,因此每次都需要傳入資料。 現在就要換一種開發思路。
-------------------------------------------------------------------
http://www.cnblogs.com/artech/archive/2007/04/06/702658.html
淺談ASP.NET的Postback
點擊一個button的postback:
代碼<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTA0NDQ2OTE5OWRk281L4eAk7iZT10hzg+BeOyoUWBQ=" />
Server端通過__EVENTTARGET這個hidden field的值找到對應的Server端的Control
那麼調用Page的RaisePostBackEvent方法
代碼[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
sourceControl.RaisePostBackEvent(eventArgument);
}
代碼protected virtual void RaisePostBackEvent(string eventArgument)
{
base.ValidateEvent(this.UniqueID, eventArgument);
if (this.CausesValidation)
{
this.Page.Validate(this.ValidationGroup);
}
this.OnClick(EventArgs.Empty);
this.OnCommand(new CommandEventArgs(this.CommandName, this.CommandArgument));
}
這篇文章,大概知道,通過hiddenfield + input,伺服器反射擷取對象,然後指定介面觸發調用。問題就在於,是否一個httpHandler反射對象然後載入? 還是有很多個?
http://www.cnblogs.com/artech/archive/2007/05/21/753620.html
深入剖析ASP.NET的編譯原理之一:動態編譯(Dynamical
Compilation)
asp.net裡面一個page1。動態編譯為:
Page1和Page2的編譯後的Type name變成了part_i_page1_aspx& Page1和part_i_page2_aspx& Page2
在part_i_page1_aspx中定義了一個基於aspx的HttpHandler所需的所有操作,並且它繼承了Page1。
對Part I/Page1的Http Request,ASP.NET所要做的就是產生一個part_i_page1_aspx來Handle這個request就可以了。
還有一個FastObjectFactory, 高效的產生對象。而產生的是什麼樣的對象呢?實際上就是基於每個aspx的Http request的Http handler,對於Part I/Page1就是我們上面一節分析的part_i_page1_aspx對象。
一個頁面,會對應一個handler,這個handler包含了頁面的所有對象(textbox....) ,而且這些對象是動態產生的。被反射調用。
現在我們來總結整個動態編譯的過程:
Step1:當ASP.NET收到對於某個Page的Request,根據這個request對應的Url試著找到該page對應的Preservation File,如果沒有找到,重新編譯Page所在目錄下的所有需要編譯的檔案,同時產生一些額外的檔案,包括Preservation File。
Step2:然後解析這個Preservation File,通過hash和filehash判斷檔案自身或者是Dependent File是否在上一次編譯之後進行過任何的修改,如果是的,則重新編譯。然後重新執行Step2。
Step3:通過Preservation File 的assembly attribute Load對應的assembly(如果Assembly還沒有被Load的話),通過type獲知對應的aspx type,然後藉助FastObjectFactory的對應的Create_ASP_XXX建立這個type。這個新建立的對象就是我們需要的Http Handler,在之上執行相應的操作把結果Response到用戶端。
-------------------------------------------------------------------
http://www.theserverside.net/tt/articles/showarticle.tss?id=IIS_ASP
Inside IIS & ASP.NET
IIS communicates with the .NET framework through unmanaged ISAPI extensions: aspnet_isapi.dll and aspnet_filter.dll.
along with the state Windows service (aspnet_state.exe) and the ASP.NET worker process (aspnet_wp.exe) are the core of the ASP.NET processing model.
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory"/>
Implementing IHttpHandlerFactory
Where HTTP handlers may be useful in responding to requests for specific resources, a handler factory makes it possible to intercept a request, perform some pre-processing on the request, and then following a factory pattern, create the handler for the resource.
-----------------------------------------------------------------------
http://msdn.microsoft.com/en-us/library/ms972976.aspx
Understanding ASP.NET View State
View state's purpose in life is simple: it's there to persist state across postbacks.
-----------------------------------------------------------------------
ASP.NET MVC 入門:
http://www.cnblogs.com/qleelulu/archive/2008/10/05/1303997.html
/Views/{Controller}/{Action}.aspx
asp.net mvc 的頁面實際上是一些<%% > 進行模板解析。
Q:在mvc中,如何才持久資料?例如在後台擷取某個txtbox的text?
理論上是無法擷取的。因為是無狀態的,除非請求主動發送。
-----------------------------------------------------------------------
http://www.cnblogs.com/jmtek/archive/2006/02/16/331961.html
ASP.NET運行模式:PageHandlerFactory
JS架構如何和伺服器互動?
------------------------------------
http://www.pin5i.com/showtopic-20894.html
ExtJS 中使用Asp.net編寫後台伺服器程式的幾種方式
1. wcf
2. 寫一個aspx,在page_load裡面對request的string進行switchcase
3. 繼承httphandler, 反射method進行操作。
http://tech.it168.com/a2010/0106/833/000000833411.shtml
現有的Ajax從架構角度分級的話,可以有以下分類:
·零級,完成base工作,包括擴充原有對象的方法,Ajax通訊部分,比較精簡。
·一級,完成effect工作,包括增加常用效果轉換函式,如tween、drag、maskLayer、fade等的特效。
· 二級,完成component工作,包括對話方塊、列表、樹、日曆等的組件。
·三級,完成application工作,包括完整的前端平台,允許使用者定義能實現一定功能的模組。
一些架構只做零級,如Prototype.js,一些架構做到一級,如jQuery ,一些架構做到了三級,如Asp.net Ajax 和EXT。
選擇合適的Ajax架構能提升程式效率,減少開發工作量,最佳化顯示效果等作用。
---------------------------------------
理想中的開發架構:
1. 使用js實現智能參數回傳(js+hidden input + 反射方法體需要的對象id產生回調傳入參數)
private void onclick()
{
string username = Postback["id"] ; // 這裡得知控制項id,然後產生html頁面的時候動態產生js進行智能回調,實現高效能viewstate
}
2. 使用asp.net / c#作為服務端技術。
不使用asp.net的項目,版本維護、代碼關聯很困難。直接使用類庫進行服務端編寫。因此需要實現factory。
asp.net 指定了assembly, classname
用戶端返回請求 Action.aspx, 映射成為metod.
3.