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();
        }
  • 相关阅读:
    魔方
    js烟花特效
    面试cookie
    扩展日期插件
    通过javascript实现1~100内能同时被2和3整除的数并生成如下表格
    用三或四个个div标签实现工字效果
    2015_WEB页面前端工程师_远程测题_东方蜘蛛_1
    js公有、私有、静态属性和方法的区别
    Docker libnetwork(CNM)设计简介
    kubernetes,Docker网络相关资料链接
  • 原文地址:https://www.cnblogs.com/yvesliao/p/889058.html
Copyright © 2011-2022 走看看