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的更多相关文章

  1. ASP.NET Core应用针对静态文件请求的处理[3]: StaticFileMiddleware中间件如何处理针对文件请求

    我们通过<以Web的形式发布静态文件>和<条件请求与区间请求>中的实例演示,以及上面针对条件请求和区间请求的介绍,从提供的功能和特性的角度对这个名为StaticFileMidd ...

  2. (转)asp.net实现忘记密码找回的代码

    1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...

  3. CSharp 相关知识点小结

    1.JS获取iframe下面的内容document.getElementById('IFRAME1').contentDocument; 2.dialog 弹出层,定位:postion:'bottom ...

  4. StaticFileMiddleware中间件如何处理针对文件请求

    StaticFileMiddleware中间件如何处理针对文件请求 我们通过<以Web的形式发布静态文件>和<条件请求与区间请求>中的实例演示,以及上面针对条件请求和区间请求的 ...

  5. loadrunner监控度量项及中文解释

    1. Number of Concurrent Users (NCU) 并发用户数 – 在指定时刻,系统观察到的并发用户连接数. 2. Request Per Second (RPS) 每秒处理请求数 ...

  6. .NET 微信开放平台接口(接收短信、发送短信)

    .NET 微信开放平台接口(接收短信.发送短信) 前两天做个项目用到了微信api功能.项目完成后经过整理封装如下微信操作类. 以下功能的实现需要开发者已有微信的公众平台账号,并且开发模式已开启.接口配 ...

  7. 密码学笔记-一段base64wp

    CTF--练习平台 例题: 一段Base64 flag格式:flag{xxxxxxxxxxxxx} 附件: base64.txt 1.base64解码:http://base64.xpcha.com/ ...

  8. ASP.NET MVC5+EF6+EasyUI 后台管理系统(63)-Excel导入和导出-自定义表模导入

    系列目录 前言 上一节使用了LinqToExcel和CloseXML对Excel表进行导入和导出的简单操作,大家可以跳转到上一节查看: ASP.NET MVC5+EF6+EasyUI 后台管理系统(6 ...

  9. 第63章 ASP.NET Identity 支持 - Identity Server 4 中文文档(v1.0.0)

    提供了基于ASP.NET身份的实现,用于管理IdentityServer用户的身份数据库.此实现是IdentityServer中的扩展点,以便为用户加载身份数据以将声明发送到令牌. 这个支持的仓储位于 ...

  10. ASP.NET MVC5+EF6+EasyUI 后台管理系统(63)-WebApi与Unity注入

    系列目录 前言: 有时候我们系统需要开放数据给手机App端或其他移动设备,不得不说Asp.net WebApi是目前首选 本节记录Asp.net MVC WebApi怎么利用Unity注入.系列开头已 ...

随机推荐

  1. ELK 集群升级操作

    1.配置项变更  2.禁用自动分片 disabled shard allocation curl -XPUT 'localhost:9200/_cluster/settings?pretty' -H ...

  2. nginx错误集合

    遇到 nginx: [warn] server name "http://127.0.0.1" has suspicious symbols in D:\nginx-1.12.1/ ...

  3. Win记录-配置Windows Server R 2008多用户远程连接(仅做参考)

    1.计算机管理下用户组下新建用户 2.系统属性下远程控制加入用户,设置允许运行任何远程桌面 3.运行->gpedit.msc->计算机配置->管理模板->windows 组件- ...

  4. jquery扩展代码少的分页bar

    直接上图,上代码了,代码量少,不解释那么多了 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" ...

  5. Pool多进程示例

    利用Pool类多进程实现批量主机管理 #!/usr/bin/python # -*- coding: UTF-8 -*- # Author: standby # Time: 2017-03-02 # ...

  6. elasticsearch 基本配置

    基本配置elasticsearch的config文件夹里面有两个配置文件:elasticsearch.yml .logging.yml.jvm.options 第一个是es的基本配置文件,第二个是日志 ...

  7. Linux之包管理工具总结[RPM/DPKG]-[YUM/APT]

    0.关键词解释 RPM:Red Hat Package Manager(原名),RPM Package Manager(现名,递归缩写,类似于GNU的命名); 解释:RPM软件包管理器 YUM:Yel ...

  8. K - Find them, Catch them POJ - 1703 (带权并查集)

    题目链接: K - Find them, Catch them POJ - 1703 题目大意:警方决定捣毁两大犯罪团伙:龙帮和蛇帮,显然一个帮派至少有一人.该城有N个罪犯,编号从1至N(N<= ...

  9. python 错误--UnboundLocalError: local variable '**' referenced before assignment

    val = 9 def test(flag): if flag: val = 1 else: print("test") return val if __name__ == '__ ...

  10. linux笔记_day05

    1.bash以及特性 shell:外壳 GUI:KDE,Gnome,Xfce CLI:sh,csh,ksh,bash(born again shell) 进程:在每个进程看来,当前主机上只存在内核和当 ...