• 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();
        }
  • 相关阅读:
    ubuntu install gobgp
    ubunut install golang
    Using GoBGP as an IXP connecting router
    400 行 C 代码实现一个虚拟机
    IPv6 Segment Routing (SRv6)
    How to Install VPP in ubuntu x86 or arm64
    mpls + sr + bgp
    ospf sr
    520了,用32做个简单的小程序
    FPGA设计经验总结
  • 原文地址:https://www.cnblogs.com/yvesliao/p/889058.html
Copyright © 2020-2023  润新知