Validation of viewstate MAC failed caused by missing session id in cookie
2023-09-11 14:14:17 时间
Resolving view state message authentication code (MAC) errors
一个有趣的 ”Validation of viewstate MAC failed” 错误的发现和解决
原来这个服务器第一次回复时,对客户端的HTTP Header里面根本没有Set-Cookie字段。
这是没有赋予Session 变量时ASP.NET的缺省行为 ( SessionID每次请求都会形成,但是未必会发送Set-Cookie 来让客户端保留这个SessioID,除非有赋予Session变量的行为)
于是解决这个问题的直接方法就是在这个Page_Init里面第一时间加一个语句:
protected void Page_Init(object sender, EventArgs e)
{
this.ViewStateUserKey = this.Session.SessionID;
session("forViewSate")="value"
}
这样服务器把SessionID在”Set-Cookie”里发送回去,客户端也可以用Cookie保留SessionID。问题就立刻解决了。
最终排查结果
发现是客户错误地在kentico的CMSPages\PortalTemplate.aspx.cs里面添加了清除response header的代码导致的
protected override void OnPreRenderComplete(EventArgs e)
{
base.OnPreRenderComplete(e);
Response.ClearHeaders();
Response.CacheControl = "private";
}
https://docs.microsoft.com/en-us/answers/questions/558746/aspnet-sessionid.html
相关文章
- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)
- Invocation of init method failed; nested exception is java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
- VS2015安装 Secondary Installer Setup Failed求解决方案
- [置顶] apt-get update 更新失败----如何清除破损而且陈旧的PPA仓库 (W: Failed to fetch http://ppa.launchpad.net/jonathonf/pyt)
- WSL(Linux子系统) gedit 报错 failed to commit changes to dconf: Failed to execute child process “dbus-launch” (No such file or directory)
- 解决Nginx的connect() to 127.0.0.1:8080 failed (13: Permission denied) while connect
- EasyNVR摄像机网页直播之问题解决:Failed:SYSTEMCurrentCont......ApplicationEasyNVR_Service registry key already
- how to deal with error message Failed to create note
- Android的报错提示:Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.2
- 成功解决NotFoundError (see above for traceback): Failed to create a directory: ; No such file or directo
- 成功解决NotFoundError (see above for traceback): Failed to create a directory: ; No such file or directo
- 已解决ImportError: numpy.core.multiarray failed to import
- 问题解决:Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorlist:...
- appium===报错Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.的解决办法
- Solving environment: failed错误解决方法
- Android Studio解决:Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed