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.
精彩评论