asp.net 登陆 前台 后台源代码

发布时间:2020-07-15 12:56:40 作者:切你小JJ
来源:网络 阅读:533

 前台代码:

<head>
    <title></title>
     <style type="text/css">
        body {font:12px Helvetica, Arial, sans-serif;  margin:100px auto; padding:0; word-wrap:break-word; word-break:break-all; background-color:#016BA9;}
        .login1{background-p_w_picpath: url(../Images/login_1.jpg); width:960px; height:94px; margin:0 auto;}
        .login2{background-p_w_picpath: url(../Images/login_2.jpg); width:960px; height:49px; margin:0 auto; }
        .login3{background-p_w_picpath: url(../Images/login_3.jpg); width:960px; height:125px; margin:0 auto;}
        .login4{background-p_w_picpath: url(../Images/login_4.jpg); width:960px; height:91px; margin:0 auto;}
        .loginTXT{border: 1px solid #800000; width:150px; background-color:#866961; color:#fff; height:19px;}
    </style>
      <script type="text/javascript">
          if (top.location != self.location)
              top.location = self.location; 

          function CheckIn() {
              var names = document.getElementById("txtU_Name").value;
              var pass = document.getElementById("txtU_Pass").value;
              var check = document.getElementById("txtU_Check").value;
              if (names == "") {
                  alert("请输入用户名...");
                  document.getElementById("txtU_Name").focus();
                  return false;
              }
              else if (pass == "") {
                  alert("请输入用户密码...");
                  document.getElementById("txtU_Pass").focus();
                  return false;
              }
              else if (check == "") {
                  alert("请输入验证码...");
                  document.getElementById("txtU_Check").focus();
                  return false;
              }
          }
    </script>
</head>
<body>
<form id="form1" runat="server" defaultfocus="txtU_Name" defaultbutton="BtnLogin">
    <div class="login1"></div>
    <div class="login2"></div>
    <div class="login3">
           <table cellpadding="0" cellspacing="1" border="0" style="margin-left:320px; width:300px;">
    <tr>
        <td>用户名称:</td>
        <td> <asp:textbox ID="txtU_Name" runat="server" class="loginTXT"   maxlength="20"></asp:textbox></td>
    </tr>
    <tr>
        <td>用户密码:</td>
        <td> <input id="txtU_Pass" type="password"  runat="server" class="loginTXT" maxlength="6"/></td>
    </tr>
    <tr>
        <td>验证代码:</td>
        <td><asp:textbox ID="txtU_Check" runat="server" class="loginTXT" style="width:85px;" maxlength="5"/>&nbsp;<img src="../VateImage.ashx" onclick="this.src='../VateImage.ashx?'+ new Date().getTime()" alt="看不清楚再换一张!" style="vertical-align:middle;"/></td>
    </tr>
    <tr>
        <td colspan="2"><hr /></td>
    </tr>
    <tr>
        <td></td>
        <td>
            <asp:button ID="BtnLogin" runat="server" text="登录管理" OnClientClick="return CheckIn()" onclick="BtnLogin_Click" />
             &nbsp;<asp:button ID="BtnHome" runat="server" text="返回首页" 
                onclick="BtnHome_Click" />
        </td>
    </tr>
   </table>
    </div>
    <div class="login4"></div>
    </form>
</body>
</html>

 

 

 

 

 

后台代码:

 

 

 protected void BtnLogin_Click(object sender, EventArgs e)
    {
        string username = txtU_Name.Text;
        string pwd = txtU_Pass.Value;
        string check = txtU_Check.Text;

        if (CheckNull())
        {
            if (check.ToString().ToLower() == Session["ValidateCode"].ToString().ToLower())
            {
                string strsql = "select count(1) from Login where UserName='" + username + "' and UserPwd='" + pwd + "'";
                object obj = SqlHelper.ExecuteScalar(ConfigurationManager.ConnectionStrings["conn"].ToString(), CommandType.Text, strsql);
                if (obj != null && (int)obj > 0)
                {
                    Response.Write("<script> alert('登录成功!')</script>");
                    Session["username"] = username;

                    HttpCookie hc = new HttpCookie("username", username);
                    hc.Expires = DateTime.Now.AddMinutes(1);
                    Response.Cookies.Add(hc);

                    Response.Redirect("Main.aspx");
                }
                else
                {
                    Response.Write("<script> alert('用户名或密码错误!')</script>");
                    Response.Write("<script>window.location.href='Login.aspx'</script>");
                }
            }
            else
            {
                Response.Write("<script> alert('验证码错误!')</script>");
                Response.Write("<script>window.location.href='Login.aspx'</script>");

            }
        }


    }
    private bool CheckNull()
    {
        return (!(string.IsNullOrEmpty(txtU_Name.Text.Trim())) && !(string.IsNullOrEmpty(txtU_Pass.Value.Trim())) && !(string.IsNullOrEmpty(txtU_Check.Text.Trim()))) ? true : false;
    }

 

main主页代码:page_Load

 try
        {
            string username = Session["username"].ToString();
        }
        catch
        {
            Response.Write("<script>alert('请从主页面登录!');location.href='Login.aspx';</script>");
        }

 

 

推荐阅读:
  1. ASP.NET中前台javascript与后台代码调用
  2. 关于asp.net前台js调用后台方法的问题

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

源代码 验证 asp.net 登陆

上一篇:类似系统的UIActivityViewController显示方式的开源代码:HYActivityView

下一篇:Go语言中的控制语句

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》