清除VIEWSTATE
问题:
1.mac错误machinekey 2.IsPostBack总是为FALSE,3.无效的视图状态viewstate
错误信息: 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate。
也就是从A页面提交到B页面,form submit时将A页面的__VIEWSTATE和__VIEWSTATEGENERATOR一起post到B页面,出现验证视图状态 MAC 失败。
方法:
//将.net控件设置为disabled,则这些控件不会被提交
方案:
function setViewDisable(_form) {
//var _form = $("#form1");
var _VIEWSTATE = _form.find("#__VIEWSTATE"); //“__VIEWSTATE”和“__EVENTTARGET”和“__VIEWSTATEFIELDCOUNT
var _EVENTTARGET = _form.find("#__EVENTTARGET");
var _VIEWSTATEFIELDCOUNT = _form.find("#__VIEWSTATEFIELDCOUNT");
var _VIEWSTATEGENERATOR = _form.find("#__VIEWSTATEGENERATOR");
_VIEWSTATE.attr("disabled", "disabled");
_EVENTTARGET.attr("disabled", "disabled");
_VIEWSTATEFIELDCOUNT.attr("disabled", "disabled");
_VIEWSTATEGENERATOR.attr("disabled", "disabled");
}
function setViewEnable(_form) {
//var form = $("#form1");
var _VIEWSTATE = _form.find("#__VIEWSTATE"); //“__VIEWSTATE”和“__EVENTTARGET”和“__VIEWSTATEFIELDCOUNT
var _EVENTTARGET = _form.find("#__EVENTTARGET");
var _VIEWSTATEFIELDCOUNT = _form.find("#__VIEWSTATEFIELDCOUNT");
var _VIEWSTATEGENERATOR = _form.find("#__VIEWSTATEGENERATOR");
_VIEWSTATE.removeAttr("disabled");
_EVENTTARGET.removeAttr("disabled");
_VIEWSTATEFIELDCOUNT.removeAttr("disabled");
_VIEWSTATEGENERATOR.removeAttr("disabled");
}