zoukankan      html  css  js  c++  java
  • ASP.NET 登录验证 sansan

    配置Web.Config 来验证当前登录,不管运行哪个页面,只要没有登录都会自动跳转到登录Login.aspx页面

    Web.Config:

        <system.web>
            <authorization>
                <deny users="?"/>
            </authorization>

          <authentication mode="Forms">
                  <forms loginUrl="Login.aspx" timeout="2880" defaultUrl="Default.aspx" />

              </authentication>

           </system.web>

    Login.aspx.cs

      

    protected void btnLogin_Click(object sender, EventArgs e)
            {

                string userName = txtUserName.Text;
                string userPwd = txtUserPwd.Text;

                UserInfo userObj = userOper.CheckLogin(userName, userPwd);
                if (userObj == null)
                    Response.Write("<script>alert('用户名或密码错误!');</script>");
                else
                {
                    Session["UserInfo"] = userObj;
                   
                    FormsAuthentication.SetAuthCookie(userObj.UserName, false);
                    Response.Cookies.Add(new HttpCookie("UserName", userObj.UserName));
                    Response.Redirect(FormsAuthentication.DefaultUrl);
                }
            }

  • 相关阅读:
    splinter webdriver API 的基本实现
    201253 线程和进程的区别
    Winform中的默认图片
    [收藏】正确使用SqlConnection对象,兼谈数据库连接池
    手机相关的基础名称
    常见排序
    SIP相关内容
    How to set the WIFI configuration
    本地化的设置和读取
    Serialize And Deserialize Binary Tree
  • 原文地址:https://www.cnblogs.com/liushanshan/p/1918107.html
Copyright © 2011-2022 走看看