步步为营-63-Asp.net-get与post
1 get
Get方式将数据发送到服务端,那么会将用户在表单中的数据放置到浏览器的地址栏中发送到服务器
格式:表单元素name属性的值=用户输入的值
请求地址:http://localhost:59448/GetAndPost.ashx?txtName=123&txtPwd=123
接收方式: string userName = context.Request.QueryString["txtName"];//接收表单元素name的值

2 Post
Post方式将数据发送到服务端,那么会将用户在表单中的数据放置请求报文体中发送到服务器
格式:表单元素name属性的值=用户输入的值
请求地址:http://localhost:59448/GetAndPost.ashx
接收方式:string userName = context.Request.Form["txtName"];//接收表单元素name的值

3 HTML 页和.ashx的相互合作
//读取模板文件
string filePath = context.Request.MapPath("AddSelf.html");
string fileContent = File.ReadAllText(filePath);
context.Response.Write(fileContent);
4 现在来做一个自增的效果页面

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form method="post" action="AddSelf.ashx">
<input type="text" name="txtNum" value="&num"/>
<input type="submit" value="计算"/>
</form>
</body>
</html>
Html
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web; namespace ASP.NETTest
{
/// <summary>
/// AddSelf 的摘要说明
/// </summary>
public class AddSelf : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
//读取模板文件
string filePath = context.Request.MapPath("AddSelf.html");
string fileContent = File.ReadAllText(filePath);
//获取文本框的值
int num;
if (Int32.TryParse(context.Request.Form["txtNum"].ToString(),out num))
{
//设置文本框的值加1
num++;
}
//替换文本框的值
fileContent = fileContent.Replace("&num",num.ToString()); context.Response.Write(fileContent);
} public bool IsReusable
{
get
{
return false;
}
}
}
}
AddSelf
5 改进一下,通过span标签展示
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form method="post" action="AddSelf.ashx">
<span>&num</span>
<input type="submit" value="计算"/>
<input type="hidden" name="hidName" value="" />
<input type="hidden" name="hidResult" value="&num" />
</form>
</body>
</html>
Html
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web; namespace ASP.NETTest
{
/// <summary>
/// AddSelf 的摘要说明
/// </summary>
public class AddSelf : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
//读取模板文件
string filePath = context.Request.MapPath("AddSelf.html");
string fileContent = File.ReadAllText(filePath);
//获取文本框的值
int num;
if (Int32.TryParse(context.Request.Form["hidResult"], out num))
{
//设置文本框的值加1
num++;
}
//替换文本框的值
fileContent = fileContent.Replace("&num",num.ToString()); context.Response.Write(fileContent);
} public bool IsReusable
{
get
{
return false;
}
}
}
}
AddSelf

步步为营-63-Asp.net-get与post的更多相关文章
- ASP.NET Core应用针对静态文件请求的处理[3]: StaticFileMiddleware中间件如何处理针对文件请求
我们通过<以Web的形式发布静态文件>和<条件请求与区间请求>中的实例演示,以及上面针对条件请求和区间请求的介绍,从提供的功能和特性的角度对这个名为StaticFileMidd ...
- (转)asp.net实现忘记密码找回的代码
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...
- CSharp 相关知识点小结
1.JS获取iframe下面的内容document.getElementById('IFRAME1').contentDocument; 2.dialog 弹出层,定位:postion:'bottom ...
- StaticFileMiddleware中间件如何处理针对文件请求
StaticFileMiddleware中间件如何处理针对文件请求 我们通过<以Web的形式发布静态文件>和<条件请求与区间请求>中的实例演示,以及上面针对条件请求和区间请求的 ...
- loadrunner监控度量项及中文解释
1. Number of Concurrent Users (NCU) 并发用户数 – 在指定时刻,系统观察到的并发用户连接数. 2. Request Per Second (RPS) 每秒处理请求数 ...
- .NET 微信开放平台接口(接收短信、发送短信)
.NET 微信开放平台接口(接收短信.发送短信) 前两天做个项目用到了微信api功能.项目完成后经过整理封装如下微信操作类. 以下功能的实现需要开发者已有微信的公众平台账号,并且开发模式已开启.接口配 ...
- 密码学笔记-一段base64wp
CTF--练习平台 例题: 一段Base64 flag格式:flag{xxxxxxxxxxxxx} 附件: base64.txt 1.base64解码:http://base64.xpcha.com/ ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(63)-Excel导入和导出-自定义表模导入
系列目录 前言 上一节使用了LinqToExcel和CloseXML对Excel表进行导入和导出的简单操作,大家可以跳转到上一节查看: ASP.NET MVC5+EF6+EasyUI 后台管理系统(6 ...
- 第63章 ASP.NET Identity 支持 - Identity Server 4 中文文档(v1.0.0)
提供了基于ASP.NET身份的实现,用于管理IdentityServer用户的身份数据库.此实现是IdentityServer中的扩展点,以便为用户加载身份数据以将声明发送到令牌. 这个支持的仓储位于 ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(63)-WebApi与Unity注入
系列目录 前言: 有时候我们系统需要开放数据给手机App端或其他移动设备,不得不说Asp.net WebApi是目前首选 本节记录Asp.net MVC WebApi怎么利用Unity注入.系列开头已 ...
随机推荐
- C# 中对于json的解析小结
1.解析之前的json格式 [{ "Name": "冯111", "PID": "130627199202283306" ...
- js/jquery控制页面动态加载数据 滑动滚动条自动加载事件--转他人的
js/jquery控制页面动态加载数据 滑动滚动条自动加载事件--转他人的 相信很多人都见过瀑布流图片布局,那些图片是动态加载出来的,效果很好,对服务器的压力相对来说也小了很多 有手机的相信都见过这样 ...
- IntelliJ IDEA AndroidStudio SVN无法使用
1.Cann't Run Program "SVN" 把勾都去掉,结果没有任何反应.2.重新安装TotoriseSVN,设置Svn.exe路径,主要不要勾选Enable Inter ...
- Tomcat数据源的原理,配置及使用(JNDI)
Tomcat数据源的原理,配置及使用 知识点: 1.数据源的作用及操作原理; 2.Tomcat中数据源的配置; 3.数据源的查找及使用 传统JDBC使用过程存在以下四个步骤: 1.加载驱动程序 2.进 ...
- SQL语句——重复记录
1.查找重复记录: (按id查找) select * from user_info where id in ( select id from user_info group by id ) 即:sel ...
- 20155237 2016-2017-2 《Java程序设计》第8周学习总结
20155237 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 NIO与NIO2 认识NIO Channel: 衔接数据节点(与IO中的流对比) isOpe ...
- elasticsearch 单机多实例
elasticsearch 配置单机器多实例 host: - - path data: /opt/elasticsearch/data/node1 /opt/elasticsearch/data/no ...
- 堆叠窗口QStackedWidget
经常将QStackedWidget和QListWidget或者QListView搭配使用 import sys from PyQt5.QtWidgets import QApplication, QW ...
- 第18月第10天 iOS11 uicollectionview
1. - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollect ...
- Spring源码学习资料
未完待续.. github地址 https://github.com/spring-projects 学习地址 https://github.com/code4craft/tiny-spring 推荐 ...