博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ashx的学习
阅读量:7120 次
发布时间:2019-06-28

本文共 3843 字,大约阅读时间需要 12 分钟。

原文:

                嘿嘿,今天我们休息,本来是想总结一下前两周学习的javascript和jquery,但是感觉好困哦,就没有认真地学习啦,于是做了一个小小的练习,刚开始学习html使用在项目中还是蛮高兴的啦,下面就简单的总结一下这个小小的登录页面。

         一.html的静态页面

用户名:
密  码:

                    这里是写了一个简单的html页面,实现其登录界面的样式。

                     二.ashx的文件代码

using System;using System.Web;using System.IO;using UseiInfoModel;using UserInfoBll;public class first : IHttpHandler {         public void ProcessRequest (HttpContext context) {        context.Response.ContentType = "text/html";          //接受的是html格式的文档        string path = context.Request.MapPath("FirstHtml.html");   //获取文档的路径        string html = File.ReadAllText(path);               //读取文档        context.Response.Write(html);         //然后写入,即返回给我们的是html页面                    string name=context.Request.Form["txtname"];     //获取txtname        string pwd = context.Request.Form["txtpwd"];    //获取txtpwd        if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(pwd))    //当文本框不为空        {            Userinfobll bll = new Userinfobll();            Userinfomodelcs model = bll.GetLoginByNamePwd(name, pwd);   //调用数据            if(bll!=null&&string.IsNullOrEmpty(model.Username)&&string.IsNullOrEmpty(model.Pwd))            {                context.Response.Clear();                context.Response.Write("欢迎" + model.Username + "登陆成功");    //相应报文            }        }    }       public bool IsReusable {        get {            return false;        }    }}

                这就是新学习ashx文件,实现请求报文和响应报文。在这里实现了html与服务器的交互。

                 三.bll层和dal层的代码

public class Userinfobll    {        Userinfodal dal = new Userinfodal();        public Userinfomodelcs GetLoginByNamePwd(string name, string pwd)        {            return dal.GetLoginByNamePwd(name,pwd);        }    }
public class Userinfodal    {        public Userinfomodelcs GetLoginByNamePwd(string name,string pwd)        {
//Id, Username, Pwd string sql = "select Id,Username,Pwd from UserLogin where Username=@name and Pwd=@pwd"; SqlParameter[] parms ={ new SqlParameter("@name",name), new SqlParameter("@pwd",pwd) }; SqlDataReader reader= DBHelp.ExecuteReader(sql,parms); Userinfomodelcs model = new Userinfomodelcs(); if (reader.Read()) { model.Id = Convert.ToInt32(reader[0]); model.Username = reader[1].ToString(); model.Pwd = reader[1].ToString(); } return model; } }
public static class DBHelp    {        private static string connection = ConfigurationManager.ConnectionStrings["sql"].ToString();        public static SqlDataReader ExecuteReader(string sql, params SqlParameter[] parms)        {            SqlConnection conn = new SqlConnection(connection);            conn.Open();            using (SqlCommand cmd = new SqlCommand())            {                cmd.CommandText = sql;                cmd.Parameters.AddRange(parms);                cmd.Connection = conn;                cmd.CommandType = CommandType.Text;                cmd.CommandTimeout = 5;                return cmd.ExecuteReader(CommandBehavior.CloseConnection);            }        }    }
public class Userinfomodelcs    {
//Id, Username, Pwd public int Id { set; get; } public string Username { set; get; } public string Pwd { set; get; } }

               嘿嘿,一直以为使用aspx实现其数据的提交与响应,今天学习了ashx感觉这个很奇怪,使用起来还是蛮不熟悉的,首先在实现其代码的过程中感觉不是直接和页面交互,而是一切和数据有关的和页面和有关的都要去实现,并不是很简单的那样,嘿嘿,这只是个人的意见,不知道大家在学习这个时间是不是这样的感觉那,怎么说那?可能接下来我们要学习ajax,学习完这个就好多啦,与页面的交互会更加的方便吧,但是之前也没怎么接触ajax,只是看到啦和js中使用,具体的还是不了解的,就写到这里啦,最近学习的理论知识还没有总结,感觉真的是需要再给点时间理解一下,需要了解清楚在总结。要继续努力!

 

转载地址:http://zxsel.baihongyu.com/

你可能感兴趣的文章
gvim设置字体和隐藏菜单栏工具栏
查看>>
php用curl获取远端网页内容
查看>>
selenium+python谷歌驱动配置
查看>>
oralce的function处理考勤时间节点以及计算工作时间
查看>>
(三)、一步一步学GTK+之布局
查看>>
43. ExtJs控件属性配置详细
查看>>
ros名称、命名空间和重映射
查看>>
系统进程查看 --- 微软官方出品
查看>>
Python 第三方模块安装出现的问题和解决方案.
查看>>
实验1
查看>>
CF915E Physical Education Lessons(珂朵莉树)
查看>>
洛谷P5050 【模板】多项式多点求值
查看>>
PhoneGap
查看>>
Vue.js学习与理解
查看>>
spring this.logger.isDebugEnabled()
查看>>
leetcode-231-Power of Two
查看>>
POJ 3126
查看>>
Unity 3D中 Ulua-UGUI简单的Demo——热更新的具体流程、使用说明
查看>>
第十章:基本数据结构(2)
查看>>
php处理管道文件流
查看>>