默认情况下,ASP.NET 的 Membership 向客户端写入 Cookie,以保持会话。
登录后,ASP.NET 的 Membership 会向客户端写入一个名为 .ASPXAUTH(注意含一个点)的 Cookie,这个 Cookie 的值是一长串字符数字,这个就是会话的标识。
试验一、清除 .ASPXAUTH 就是注销
Response.Cookies.Remove(
".ASPXAUTH");
如上,我们删除了 .ASPXAUTH 这个 Cookie,在下一个页面中(本页面中还是存在的),.ASPXAUTH 将不存在,此时用户状态不再是已登录状态。
试验二、“改个名吧,师傅”
我们可以在 Web.config 的 configuration -> system.web -> authentication 改变这个 .ASPXAUTH 的名字。
<authentication
mode="Forms"
>
<forms loginUrl="~/Account/Login.aspx" timeout="2880" name="myCookie" />
</authentication >
<forms loginUrl="~/Account/Login.aspx" timeout="2880" name="myCookie" />
</authentication >
修改如下代码后,刷新页面,我们可以发现虽然 .ASPXAUTH 仍然存在,但它已经是过往云烟,不再起作用,只是没人去清除它罢了,新的标识 Cookie 名称是 myCookie。