ASP.NET登录接口

这是效果图实现:

这里是数据库的链接:

<?xml version="1.0" encoding="utf-8"?>
<!--
  有关如何配置 ASP.NET 应用程序的详细信息,请访问
  https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
  </system.web>
    <connectionStrings>
        <add name="constr" connectionString="server=.;database=hism;pwd=123456;uid=sa;"/>
        <add name="constr1" connectionString="server=.;database=hism;pwd=123456;uid=sa;"/>
    </connectionStrings>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

这是登录的的代码:

using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace helloasp
{
    public partial class defaul : System.Web.UI.Page
    {
         int i = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)  //判断是不是post请求
            {
                i = 5;
                Response.Write("第一次请求!");
                Session["times"] = 0;
                Application["lll"] = 0;  //第一次访问的时候,初始化,后面不会再执行这句。
            }
            if (CheckBox1.Checked)
            {
                HttpCookie lhc = Response.Cookies["userInfo"];
                if (lhc.Values["name"] != null)
                {
                    txtPwd.Text = lhc.Values["pwd"] + "";
                    txtUserName.Text = lhc.Values["name"] + "";
                }
            }
            else
            {
                txtPwd.Text = "";
                txtUserName.Text =  "";
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            UserBll ub = new UserBll();
            UserModel um = new UserModel();
            um.userName = txtUserName.Text;
            um.pwd = txtPwd.Text;
            if (ub.userLogin(um)!=null)
            {
                HttpCookie hc = new HttpCookie("userInfo");
                hc.Values.Add("name", um.userName);
                hc.Values.Add("sex", "男");
                hc.Values.Add("age", "12");
                hc.Values.Add("pwd",um.pwd);
                hc.Expires=DateTime.Now.AddSeconds(1000);
                //hc.Path = "/index.html"; 
                Response.Cookies.Add(hc);
                
                Response.Write("登录成功!");
                Response.Redirect("www.baidu.com");  //302
            }
            else
            {
                Session["name"] = "admin登录失败";
                Response.Write("登录失败!");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Session["times"] = int.Parse(Session["times"] + "") + 1;
            Response.Write(Session["name"]+"  "+Session["times"]);
            Application["lll"] = int.Parse(Application["lll"]+"") + 1; //每次点这个按钮就会加1,记录加数器,配置文件
            Response.Write(Session.SessionID);
            Response.Write("<br/>");
            Response.Write(Application["lll"]);
        }


        /*public bool userlogin(string username,string pwd)
        {
            string constr = "server=.;uid=sa;pwd=123456;database=hism;";
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            string sqlstr = "select count(*) from tbuser where user_name='" + username + "' and pwd='" + pwd + "'";
            SqlCommand cmd = new SqlCommand(sqlstr,conn);
            object obj=cmd.ExecuteScalar();
            int i = int.Parse(obj.ToString());
            conn.Close();
            if (i > 0)
            {
                return true;
            }

            return false;
        }*/
    }
}

@ Page Language="C#" AutoEventWireup="true" CodeBehind="defaul.aspx.cs" Inherits="helloasp.defaul" %>

这是html登录的页面样式及代码:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="js/vue.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div id="app">
            <br />
            <br />
            <br />
            <asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label>
            <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
            <br />
            <br />
            <asp:Label ID="Label2" runat="server" Text="密    码:"></asp:Label>
            <asp:TextBox ID="txtPwd" runat="server"></asp:TextBox>
            <asp:CheckBox ID="CheckBox1" runat="server" Text="是否记住密码" />
            <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="登录" />
            <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
            <br />
            <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <br />
            <input type="button" value="缓存测试" οnclick="getcookieinfo()"/>
            <%
                /*HttpCookie hc = Response.Cookies["userInfo"];
                Response.Write(hc.Values["name"]);*/

                string machinename=Server.MachineName;
                string w = Server.MapPath(".");
                int timeout = Server.ScriptTimeout;

                string ss = Server.HtmlEncode("<h1>这是编码</h1>");
                Response.Write(ss);
                ss=Server.HtmlDecode(ss);
                Response.Write(ss);

            %>
            <%=machinename %>
            <%=w %>
            <%=timeout %>
            <% Response.Write(Server.UrlDecode("http %3A%2F%2Fwww%2Emicrosoft%2Ecom")); %>
        </div>
    </form>
</body>
</html>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>登录</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js">
    </script>
</head>
<body>
    <!--<h1>Hello world!</h1>-->
    <div>
        <div>
            <span>用户名:</span><input type="text" name="username" id="username"/>
        </div>
        <div>
            <span>密码:</span><input type="text" name="pwd" id="pwd"/>
        </div>
        <div>
            <span><input type="button" id="loginbtn" value="登录" /></span>
            <span><input type="button" value="取消" /></span>
        </div>
    </div>
    <div class="outerdiv">
        <div class="innerdiv">
        </div> 
    </div>
</body>
</html>

  • 17
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值