首页 | 下载中心 | 高手学院 | 视频教程 | 书籍教程 | 模板中心 | 空间评测 | 每日代理 | 站长服务 | 高手论坛 | 
您现在的位置: 网站高手 >> 高手学院 >> 网络安全 >> 最新动态 >> 最新漏洞 >> 脚步漏洞 >> 正文 用户登录 新用户注册
使用getauthcookie改进认证cookie 作者:佚名    文章来源:不详    点击数:    更新时间:2005-5-23

web.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<authentication mode="Forms">
<forms name="AuthCookie" loginUrl="login.aspx">
<credentials passwordFormat="Clear">
<user name="swords" password="est"/>
</credentials>
</forms>
</authentication>
<customErrors mode="Off" />
<globalization requestEncoding="gb2312" responseEncoding="gb2312" />
</system.web>
</configuration>


login.aspx

<%@page language="vb"%>
<script runat="server">
sub login(obj as object,e as eventargs)
if FormsAuthentication.authenticate(tbusername.text,tbpassword.text) then
dim cookie as httpcookie
cookie=Formsauthentication.getauthcookie("swords",false)
cookie.expires=datetime.now.addminutes(2)
response.cookies.add(cookie)
'FormsAuthentication.setAuthCookie(tbusername.text,false)
lblmessage.text="success!"
else
lblmessage.text="invalid!"
end if
end sub
</script>
<html><body>
<form runat="server">
<asp:label id="lblmessage" runat="server"/>
<asp:textbox id="tbusername" runat="server" />
<asp:textbox id="tbpassword" textmode="password" runat="server" />
<asp:button id="submit" runat="server" onclick="login" text="submit"/>
</form>
</body></html>


ps:
FormsAuthentication.signout注销用户的cookie
setAuthCookie(tbusername.text,false)
false关闭浏览器自动失效,true关闭浏览器依然有效.
使用getauthcookie改进认证cookie 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)  去网站高手技术论坛讨论...
文章录入:FOX    责任编辑:FOX  【发表评论】【告诉好友】【打印此文】【关闭窗口
  • 上一篇文章: 程序员趣味读物:谈谈Unicode编码
  • 下一篇文章: 穿透防火墙的数据传输方法(附源码)