lazyload the images

最新精選 Featured post

異世界穿越作品整合

訂閱

訂閱 FB 專頁

每月雙數周日為固定發佈日

訂閱FB 專頁,有新發佈時將會立即看見。
Youtube 頻道經常會有電玩錄影

29/11/2014

ASP.NET ViewStatve and EventValidation

文章分類: , , ,

背景不想說太多,或者在一年後公開。
現在就是要找出Disable ViewStatus和EventValidation的方法。

EventValidation是ASP.NET authentication module 內的Security control

ViewStatus就是一個節省User重填資料的機制。
ViewStatus 是負責儲起傳送到伺服器的Form Value。
如果ASP.NET 當中有POST BACK,例如登入名稱密碼不正確。
在回到登入介面後,ViewStatus的值會填回Form上。

有錯請指證,小弟不是ASP.NET專家

事件告一段落,簡直如釋重負地想爆炸。

正解︰

EventValidation 只要在 EnableEventValidation set false,就可以消失在Form 中。
不論是在 level、module level、web.config中又可以。

麻煩的是ViewStatus,現實正如官方說明般殘酷。
EnableViewState set 成 false還是會出現在Form中。

大家不要參考override Render method的方法。最後是採納Moving ViewState to the Session Object的方法
===================================================================
記錄用 碎碎唸恕文
===================================================================
參考文章︰

How to Disable View State on a Page
http://www.ironspeed.com/articles/Disable%20View%20State%20for%20a%20Page/Article.aspx#gsc.tab=0
http://aspnetresources.com/articles/viewstate

<asp:Label id=Label1 runat="server" EnableViewState="false" />
<%@ Page ... EnableViewState="false" %>
<pages enableViewState="false" />

Page.EnableViewState Property
http://msdn.microsoft.com/en-us/library/system.web.ui.page.enableviewstate(v=vs.110).aspx
Even if EnableViewState is false, the page might contain a hidden view state field that is used by ASP.NET to detect a postback.

Page.EnableEventValidation Property
http://msdn.microsoft.com/en-us/library/system.web.ui.page.enableeventvalidation(v=vs.110).aspx

What is a postback?
http://stackoverflow.com/questions/4251157/what-is-a-postback

How to disable or remove ViewState Hidden Field in ASP.Net Page
http://www.aspsnippets.com/Articles/How-to-disable-or-remove-ViewState-Hidden-Field-in-ASP.Net-Page.aspx
protected override void Render(HtmlTextWriter writer)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hWriter = new HtmlTextWriter(sw);
base.Render(hWriter);
string html = sb.ToString();
html = Regex.Replace(html, "<input[^>]*id=\"(__VIEWSTATE)\"[^>]*>", string.Empty, RegexOptions.IgnoreCase);
writer.Write(html);
}
View State decoder
http://ignatu.co.uk/ViewStateDecoder.aspx

Completely remove ViewState for specific pages
http://stackoverflow.com/questions/2432972/completely-remove-viewstate-for-specific-pages
http://www.aspsnippets.com/Articles/How-to-disable-or-remove-ViewState-Hidden-Field-in-ASP.Net-Page.aspx
override Render method

http://bytes.com/topic/asp-net/answers/612329-there-any-way-avoid-__viewstate-hidden-field-page
It can't get rid completely of the __VIEWSTATE field

Moving ViewState to the Session Object and more Wrongheadedness
http://www.hanselman.com/blog/MovingViewStateToTheSessionObjectAndMoreWrongheadedness.aspx

w3c School - ASP.NET Web Forms - Maintaining the ViewState
http://www.w3schools.com/aspnet/aspnet_viewstate.asp

No comments:

Post a Comment