第一个asp.net程序

3 篇文章 0 订阅
1 篇文章 0 订阅

我学的是javaweb,最近觉得自己学的知识远远不够,所以在课余时间开始学起了c#。也想多掌握一门编程语言,对于学过java的人来说学习c#是比较简单的,asp.net也是一样。今天就来写个模仿登录的程序。这里会结合js来做开发。

首先做一个html页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
  function check(){
  
  var username=document.getElementById("name").value;
 var password=document.getElementById("password").value;

  if(username==""||password==""){
    alert("用户名或密码不能为空");
    return false;
  }
}
</script>
    <title>无标题页</title>
</head>

<body>
   <form id="form1" runat="server" action="servlet/check2.ashx" method="post">
     用户名:<input type="text" name="name"  id="name"/><br /><br />
      密码:<input type="password" name="password" id="password"/><br /><br />
      <input type="submit" value="登录" οnclick="javascript:return check()"/>
    </form>
</body>
</html>

编写一般处理程序,如果用户名和密码都是tom的打印登录成功,否则登录失败

<%@ WebHandler Language="C#" Class="check2" %>

using System;
using System.Web;

public class check2 : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
        string username = context.Request["name"];
        string password = context.Request["password"];
        if (password.Equals("tom") && username.Equals("tom"))
        {
            context.Response.Write("登录成功");
        }
        else
        {
            context.Response.Write("登录失败");
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

学习java的人可能会这么写 string username = context.Request("name").这里写成小括号就会报错


到这里程序就结束了,下面是运行效果



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值