Below you will find pages that utilize the taxonomy term “ASP.NET”
Posts
ASP.NET - Logging application shutdown events
做網站服務最害怕的就是服務不能正常運作,有時要追出實際發生的問題需要花費我們很多的時間。這時如果系統能將停止服務的原因正確的記錄下來,可有助於我們將問題快速的釐清。
可惜的是服務停止的原因預設是無法取得的,因為並沒有直接開放給開發人員調用。不過好在這樣的資訊還是有的,只是未被開出而已,所以我們仍舊可以透過反射下去取得。
要擷取這樣的資訊我們要從 HttpRuntime 類別下手,類別內有個 _theRuntime 靜態私有欄位用以存放唯一的物件實體,實體內的 _shutDownMessage 與 _shutDownStack 私有欄位分別存放著 Shutdown 的訊息與呼叫堆疊。
程式寫起來就像下面這樣:
... private void LogShutDownInfo() { if (! m_Logger.IsInfoEnabled ) return; var type = typeof (HttpRuntime ); var runtime = ( HttpRuntime) type .InvokeMember( "_theRuntime" , BindingFlags.NonPublic | BindingFlags.Static | BindingFlags .GetField, null, null , null); if (runtime == null) return; var message = ( string) type .InvokeMember( "_shutDownMessage" , BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags .GetField, null, runtime, null); var stack = ( string) type .
read morePosts
ASP.NET - Disable View State
禁用 View State 有幾種方式。若要將所有頁面都禁用,我們可以在 Web.Config 內的 system.web 加入 pages 的 element,並將其 enableViewState attribute 設為 false。
... <system.web> ... <pages enableViewState= "false"/> ... </system.web> ... 若要在單一頁面禁用,可以在該檔案最前面加入…
<%@ Page EnableViewState= "true" ViewStateMode= "Disabled" .. . %> ... 若要指定單一控制項禁用,可直接為控制項加上 EnableViewState attribute,並將其值設為 false…
... <asp:GridView ID= "gdvCustomers" runat= "server" DataSourceID= "mySqlDataSource" AllowPaging="True" EnableViewState ="false"/> ... 若要針對單一控制項啟用,頁面上其餘的控制項禁用,可以像下面這樣處理…
<%@ Page EnableViewState= "true" ViewStateMode= "Disabled" .. . %> ... <asp:GridView ID= "gdvCustomers" runat= "server" DataSourceID= "mySqlDataSource" AllowPaging="True" ViewStateMode= "Enabled"/> .
read more