ashx登陆

denglu.aspx.cs文件中:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;

public partial class denglu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string[] lines = File.ReadAllLines("password.txt");

        string username = txtUserName.Value;
        string password = passwordTxt.Value;

        for (int i = 0; i < lines.Length; i++)
        {

            string[] line = lines[i].Split(' ');
            if (username == line[0] && password == line[1])
            {
                htmlLabel1.InnerText = "登陆成功";
                return;
            }

        }

        htmlLabel1.InnerText = "登陆失败";
           
    }
}

denglu.aspx文件中:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="denglu.aspx.cs" Inherits="denglu" %>
<html xmlns="
http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style3
        {
            width: 129px;
        }
        .style4
        {
            width: 159px;
        }
    </style>
</head>
<body>
   <form id="form1" runat="server">
    <div >
    <table align="center" border="1px" style="width: 35%" >

     <tr><td class="style3">用户名:</td><td class="style4"><input type="text" id="txtUserName" runat="server"/></td></tr>
   
<tr><td class="style3">密 码:</td><td class="style4"><input type="text" id="passwordTxt" runat="server" /></td></tr>

     <tr>
         <td class="style3"><asp:Button ID="Button1" runat="server" Text="登陆" onclick="Button1_Click" /> <input type="button" id="btn1" value="html登陆" runat="server" onserverclick="Button1_Click"/></td>
         <td class="style4"><label id="htmlLabel1" runat="server"></label></td>   
     </tr>
    </table>
    </div>
    </form>
</body>
</html>

注意:

把password.txt文件放到C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\这个文件夹下,password.txt文件的编码方式为UTF-8,否则文件中的中文不能进行比较。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值