惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - boulder

Md5Encode 算法 javascript浮动图片 - boulder 导出Excel - boulder - 博客园 获取键盘的enter - boulder - 博客园 oracle 的float(b)转 oracle函数(关于处理小数点位数) char、varchar和varchar2的区别(转) - boulder - 博客园 生成验证码(转) - boulder - 博客园 ASP.NET 2.0利用Httphandler实现URL重写(伪URL及伪静态)(转) .net上传文件的限制 - boulder 电话号码的验证表达式 GridView 在换页时保持CheckBox的选择 - boulder 在DataList中找到控件 自定义datatable 没有装Express版Sql Server 2005就不能用WebPart ? (转) form表单 input 通过查询系统表得到纵向的表结构 Codebehind CodeFile转 解决flash的虚框问题 - boulder
asp.net 利用Cookie实现免登陆(c#) - boulder - 博客园
boulder · 2008-12-04 · via 博客园 - boulder

  前台
  <script language="javascript">
     function ChangeClick(id)
     {
       if(id=="1")
       {
           if( document.getElementById('<%=chbNoExpire.ClientID %>').checked==true)
           {
             document.getElementById('<%=chbNoExpire.ClientID %>').checked=false;
           }
            return false;
       }
       if(id=="2")
       {
         if(document.getElementById('<%=chbExpire.ClientID %>').checked==true)
          {
            document.getElementById('<%=chbExpire.ClientID %>').checked=false;
          }
          return false;
        }
     }
    </script>
 <p> 免登陆时间:<input type="checkbox" id="chbExpire" runat="server" onclick="ChangeClick(1);" />30天<input type="checkbox"
 id="chbNoExpire" runat="server" onclick="ChangeClick(2);" />永久
 </p>

后台:
//在第一次登陆的时候,记录cookie 并加密
protected void btnLogin_Click(object sender, EventArgs e)
{
     DateTime dtExpire = chbExpire.Checked ? DateTime.Now.AddDays(30) : DateTime.Now.AddMonths(600);

     string ip = CommonHelper.GetCurrentIP();
     string userInfo = _userEty[0].ID.ToString() + "|" + ip;
     FormsAuthenticationTicket ticket =
               new FormsAuthenticationTicket(1, "userInfo", DateTime.Now, dtExpire, false, userInfo);
     String cookieStr = FormsAuthentication.Encrypt(ticket);
      // Send the cookie to the client
      Response.Cookies["userInfo"].Value = cookieStr;
      Response.Cookies["userInfo"].Path = "/";
      Response.Cookies["userInfo"].Expires = dtExpire;
}
//退出清空cookie
    protected void btnLoginOut_Click(object sender, EventArgs e)
    {
        Session.Clear();
        HttpCookie cookie = Request.Cookies["userInfo"];
        if (cookie != null)
        {
            cookie.Expires = DateTime.Now.AddDays(-2);
            Response.Cookies.Set(cookie);
        }
        InitTab_BeforeLogin();
        ShowTabBeforeLogin();
    }
//页面加载时:
   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //设置cookie
            if (Context.Request.Cookies["userInfo"] != null)
            {
                FormsAuthenticationTicket ticket2 = FormsAuthentication.Decrypt(Context.Request.Cookies["userInfo"].Value);
                //convert the string representation of the role data into a string array
                string[] strInfo = ticket2.UserData.Split(new char[] { '|' });
                string id = strInfo[0].ToString();
                //初始化登陆后的数据
            }
     }