开发者

How to disable ControlState in ASP.NET?

开发者 https://www.devze.com 2023-01-04 20:33 出处:网络
How to completely disable ControlState in an ASP.NET website application to get rid of <input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\"/ACBDEFGH...XYZ=\" /> on every page?

How to completely disable ControlState in an ASP.NET website application to get rid of <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/ACBDEFGH...XYZ=" /> on every page?

Searching for a solution, I only found meaningless answers making no difference between ControlState and ViewState, or replies saying that "we cannot disable 开发者_C百科control state". The second assumption seems to be false, since StackOverflow pages do not have ViewState hidden field.


Create a custom class

 public class PageBase:Page
    {

        protected override void SavePageStateToPersistenceMedium(object state)
        {
                // Do nothing here
        }    

    }

Then change your page to inherit from PageBase

    public partial class Test : PageBase
    {
    }


yes, control state was meant to be a mechanism that would work even if view state was disabled, thus, its a permanent fixture of ASP.NET web forms. MVC would not have this since it doesn't utilize the viewstate or control state mechanism.

HTH.

0

精彩评论

暂无评论...
验证码 换一张
取 消