zoukankan      html  css  js  c++  java
  • FormsAuthentication最简单的使用

    登录

        protected void btnLogin_Click(object sender, EventArgs e)
        
    {
            
    string userName = "UserName";
            
    string password = "Password";
            
    if (txtUserName.Text == userName && txtPassword.Text == password)
            
    {
                setValidTime(chkRememberMe.Checked, userName);
                Response.Write(
    "<script>top.location='Default.htm';</script>");
            }

            
    else
            
    {
                labMsg.Text 
    = "登录失败,请重试";
            }

        }


        
    /// <summary>
        
    /// 设置有效时间
        
    /// </summary>

        protected void setValidTime(bool RememberMe, string strUserName)
        
    {
            
    if (RememberMe)
            
    {
                FormsAuthentication.SetAuthCookie(strUserName, 
    true);
                HttpCookie lcookie 
    = Context.Response.Cookies[FormsAuthentication.FormsCookieName];
                lcookie.Expires 
    = DateTime.Now.AddYears(1);
            }

            
    else
            
    {
                FormsAuthentication.SetAuthCookie(strUserName, 
    false);
            }

        }

    注销

        protected void btnSignOut_Click(object sender, EventArgs e)
        
    {
            FormsAuthentication.SignOut();
        }
  • 相关阅读:
    Linux文件系统结构
    JAVA实现上传下载共享文件
    JAVA 实现通过URL下载文件到本地库
    使用SoapUI 测试 Web Service
    DB2存储过程实现查询表数据,生成动态SQL,并执行
    DB2查看表空间大小及使用情况
    Spring使用总结
    Commons-logging + Log4j
    JAVA生成EXCEL图表
    html5离线缓存原理
  • 原文地址:https://www.cnblogs.com/yvesliao/p/889058.html
Copyright © 2011-2022 走看看