c# - 解决asp.net webforms中的cookie重放攻击
问题描述
按照StackOverflow 上的这个答案,微软建议执行以下操作:
- 清除 cookie。
- 将 Response.Status 属性设置为 401。
- 调用 Response.End 方法,该方法将隐式重定向到登录页面。
我在我的文件中提出了这行代码global.asax
,(我在我的用户表中添加了一个额外的字段,名为isLogin
我在登录和注销页面中设置为 true 和 false ...)
void Application_PostAuthenticateRequest(object sender, EventArgs e)
{
IPrincipal p = HttpContext.Current.User;
if (p.Identity.IsAuthenticated)
{
var userName = p.Identity.Name;
HttpCookie authenticationCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (SecurityUtilities.CheckUserLoggedIn(userName) == false)
{
FormsAuthentication.SignOut();
Response.StatusCode = 401;
Response.End();
}
}
}
我想知道我做这一切是否正确?这段代码呢?
if (SecurityUtilities.CheckUserLoggedIn(userName) == false)
{
FormsAuthentication.SignOut();
Response.Redirect(FormsAuthentication.LoginUrl);
}
解决方案
推荐阅读
- animation - Flutter 中的文本是否有水平淡入淡出功能?
- html - 位置:如果父级有溢出,则粘性不起作用:自动样式
- eclipse - Eclipse 调试器无法启动
- php - 中间件中的 Laravel 会话并不总是设置
- angular - How to order mat-select alphabetically when options have conditional names
- python - Tkinter & Turtle Etch-a-Sketch
- graphql - 更新用作全局存储的 Apollo 缓存时如何分离逻辑?
- image - 异步功能未完成
- flutter - Flutter - 如何在共享首选项加载时暂停应用程序?
- sql-server - 用更新声明回答我