代码之家  ›  专栏  ›  技术社区  ›  Rathma

解决asp.net webforms中的cookie重放攻击

  •  1
  • Rathma  · 技术社区  · 6 年前

    下列的 this 回答StackOverflow,Microsoft建议执行以下操作:

    1. 把饼干弄干净。
    2. 将Response.Status属性设置为401。
    3. 调用将隐式重定向的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);
    } 
    
    0 回复  |  直到 6 年前