ASP.Net学习笔记004--基于ashx方式的ASP.Net开发1
来源:互联网 发布:令狐公子 知乎 编辑:程序博客网 时间:2024/06/04 05:33
以前写的课程都没有附上源码,很抱歉!
课程中的源码可以加qq索要:1606841559
技术交流qq1群:251572072
技术交流qq2群:170933152
也可以自己下载:
ASP.Net学习笔记004基于hx方式的ASP.Net开发1.zip
http://credream.7958.com/down_20144363.html
用例子说明
ashx和aspx是处理前台提交数据的两种方式:
ashx:
新建/WebSite1
hello1.htm
<!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>
<title></title>
</head>
<body>
<form action="Hello1.ashx">
姓名:<input type="text" value="UserName" name="UserName"/>
<input type="submit" value="提交" />
<!--
服务器只认name属性,而且name属性如果重复,会只提交第一个
id是给dom用的
-->
</form>
</body>
</html>
---------------------------------------------------------------------------
Hello1.ashx
<%@ WebHandler Language="C#" Class="Hello1" %>
using System;
using System.Web;
public class Hello1 : IHttpHandler {
public void ProcessRequest (HttpContext context) {
// context.Response.ContentType = "text/plain";//返回的数据是txt格式的
//这里写plain可能导致,浏览器识别成xml
context.Response.ContentType = "text/html";//表示返回的数据是html
//把原来的html写到浏览器:
string username = context.Request["UserName"];//取得html端,传回的name为UserName的值
context.Response.Write(@"<form action='Hello1.ashx'>
姓名:<input type='text' value='"+username+@"' name='UserName'/>
<input type='submit' value='提交' />
</form>");//把原来的数据写到控件中
//在C#中加一个@就表示多行文本
context.Response.Write("Hello World");
context.Response.Write(username );//写回浏览器
}
public bool IsReusable {
get {
return false;
}
}
}
---------------------------------------------------------------------------
Hello2.htm
<!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>
<title></title>
</head>
<body>
<form action="Hello2.ashx">
姓名:<input type="text" value="UserName" name="UserName"/>
<input type="submit" value="提交" />
<!--
服务器只认name属性,而且name属性如果重复,会只提交第一个
id是给dom用的
-->
</form>
</body>
</html>
---------------------------------------------------------------------------
Hello2.ashx
<%@ WebHandler Language="C#" Class="Hello2" %>
using System;
using System.Web;
public class Hello2 : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
string fullPath = context.Server.MapPath("Hello2.htm");
string content = System.IO.File.ReadAllText(fullPath );
//直接访问这个文件也会被调用
context.Response.Write(content);
string username=context .Request ["UserName"];
if (string.IsNullOrEmpty (username )){
context.Response.Write("直接进入");
}
else
{
context.Response.Write("提交进入");
}
// context.Response.Write("Hello World");
}
public bool IsReusable {
get {
return false;
}
}
}
---------------------------------------------------------------------------
课程中的源码可以加qq索要:1606841559
技术交流qq1群:251572072
技术交流qq2群:170933152
也可以自己下载:
ASP.Net学习笔记004基于hx方式的ASP.Net开发1.zip
http://credream.7958.com/down_20144363.html
用例子说明
ashx和aspx是处理前台提交数据的两种方式:
ashx:
新建/WebSite1
hello1.htm
<!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>
<title></title>
</head>
<body>
<form action="Hello1.ashx">
姓名:<input type="text" value="UserName" name="UserName"/>
<input type="submit" value="提交" />
<!--
服务器只认name属性,而且name属性如果重复,会只提交第一个
id是给dom用的
-->
</form>
</body>
</html>
---------------------------------------------------------------------------
Hello1.ashx
<%@ WebHandler Language="C#" Class="Hello1" %>
using System;
using System.Web;
public class Hello1 : IHttpHandler {
public void ProcessRequest (HttpContext context) {
// context.Response.ContentType = "text/plain";//返回的数据是txt格式的
//这里写plain可能导致,浏览器识别成xml
context.Response.ContentType = "text/html";//表示返回的数据是html
//把原来的html写到浏览器:
string username = context.Request["UserName"];//取得html端,传回的name为UserName的值
context.Response.Write(@"<form action='Hello1.ashx'>
姓名:<input type='text' value='"+username+@"' name='UserName'/>
<input type='submit' value='提交' />
</form>");//把原来的数据写到控件中
//在C#中加一个@就表示多行文本
context.Response.Write("Hello World");
context.Response.Write(username );//写回浏览器
}
public bool IsReusable {
get {
return false;
}
}
}
---------------------------------------------------------------------------
Hello2.htm
<!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>
<title></title>
</head>
<body>
<form action="Hello2.ashx">
姓名:<input type="text" value="UserName" name="UserName"/>
<input type="submit" value="提交" />
<!--
服务器只认name属性,而且name属性如果重复,会只提交第一个
id是给dom用的
-->
</form>
</body>
</html>
---------------------------------------------------------------------------
Hello2.ashx
<%@ WebHandler Language="C#" Class="Hello2" %>
using System;
using System.Web;
public class Hello2 : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/html";
string fullPath = context.Server.MapPath("Hello2.htm");
string content = System.IO.File.ReadAllText(fullPath );
//直接访问这个文件也会被调用
context.Response.Write(content);
string username=context .Request ["UserName"];
if (string.IsNullOrEmpty (username )){
context.Response.Write("直接进入");
}
else
{
context.Response.Write("提交进入");
}
// context.Response.Write("Hello World");
}
public bool IsReusable {
get {
return false;
}
}
}
---------------------------------------------------------------------------
0 0
- ASP.Net学习笔记004--基于ashx方式的ASP.Net开发1
- asp.net ashx IHttpHandler
- ASP.NET【3】--ASHX
- ASP.NET【4】--ASHX
- Asp.net开发中甩掉.ashx .asmx
- asp.net中*.ashx文件的用法
- asp.net 中ashx、axd的区别
- asp.net中AngularJS+ashx的使用
- asp.net 中ashx、axd的区别
- 开发asp.net自定义控件(asp.net学习笔记二)
- 开发asp.net自定义控件(asp.net学习笔记三)
- 开发asp.net自定义控件(asp.net学习笔记四)
- 开发asp.net自定义控件(asp.net学习笔记五)
- 开发asp.net自定义控件(asp.net学习笔记三)
- asp.net的学习笔记
- asp.net ashx访问session
- ajax asp.net ashx用法
- AJAX ASP.NET ashx用法
- vimium 基本使用快捷键
- isKindOfClass和isMemberOfClass的区别
- 夏泽网 中国渔业统计年鉴年鉴资料网
- 关于scanf要写两次的问题
- 《Effective Objective-C 2.0 编写高质量iOS与OS X代码的52个有效方法》--读书笔记
- ASP.Net学习笔记004--基于ashx方式的ASP.Net开发1
- UILabel的AttributedString设置
- ASP.Net学习笔记005--ASP.Net的IsPostBack揭秘
- Java学习笔记(1)--File类、RandomAccessFile类
- 注册太麻烦,
- AFNetworking3.0使用方法
- android 开源项目整理
- 正则表达式
- Spring3 整合MyBatis3 配置多数据源 动态选择SqlSessionFactory