FormsAuthentication创建的票证无法清除,是BUG吗?

TianYi3G2013 2019-08-09 10:05:21


配置文件:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<authentication mode="Forms">
<forms loginUrl="Login.aspx" name=".AuthKey" defaultUrl="Default.aspx" cookieless="UseCookies" slidingExpiration="false"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</configuration>


登录操作:
protected void btnLogin_Click(object sender, EventArgs e)
{
var isPersistent = false;
FormsAuthentication.SetAuthCookie("admin", isPersistent);
this.Response.Redirect(FormsAuthentication.DefaultUrl);
}


退出登录操作:
protected void Page_Load(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
//清除客户端的Cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);

Session.Abandon();
//重置登录身份(没效果)
HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(string.Empty), null);
}


演示效果:
未登录前,尝试访问要求登录的页面


























难道因为FormAuth的验证机制,这个票证是无法清除的?
如果有人非法获取了AuthKey,即使用户退出且修改了密码,恶意请求AuthKey过来的话,还是可以成功登录的,需要另外增加限制?


参考资料:
FormsAuthentication.SignOut Method (System.Web.Security) | Microsoft Docs
https://docs.microsoft.com/en-us/dotnet/api/system.web.security.formsauthentication.signout?redirectedfrom=MSDN&view=netframework-4.8#System_Web_Security_FormsAuthentication_SignOut

解析ASP.NET中获取不到用户名及注销后User.Identity.IsAuthenticated值依然为true的原因-十有三博客
https://shiyousan.com/post/636409990481316726
...全文
169 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
TianYi3G2013 2019-08-13
  • 打赏
  • 举报
回复
引用 3 楼 胖叔叔写代码 的回复:
你本来就把钥匙放在cookies里面,然后从这里拿到钥匙当然可以模拟开锁了。 要么用其他方式验证,要么锁打开之后加一层验证。
如果正常过期了,即使传了“钥匙”过来,也开不了锁,那ASP.NET是如何实现原来这个钥匙过期的?
  • 打赏
  • 举报
回复
你本来就把钥匙放在cookies里面,然后从这里拿到钥匙当然可以模拟开锁了。 要么用其他方式验证,要么锁打开之后加一层验证。
TianYi3G2013 2019-08-09
  • 打赏
  • 举报
回复
Session/Authentication not removed server-side after logout | The ASP.NET Forums https://forums.asp.net/t/1988295.aspx?Session+Authentication+not+removed+server+side+after+logout
TianYi3G2013 2019-08-09
  • 打赏
  • 举报
回复
全部源码: 链接:https://pan.baidu.com/s/1fvk2MIIdVgkFH_D3q8mE5g 提取码:iil8

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧