首页 > Web开发 > 详细

ASP.Net核心对象HttpRequest

时间:2015-07-20 19:04:14      阅读:236      评论:0      收藏:0      [点我收藏+]

写一个方法获取是否含有a元素
方法一:
void Test(HttpContext context)
{
  if (!string.IsNullOrEmpty(context.Request["a"]))
  {
    context.Response.Write("你好牛");
  }
}
方法二:
void tt1()
{
  HttpContext context = HttpContext.Current;
  if (!string.IsNullOrEmpty(context.Request["a"]))
  {
    context.Response.Write("你好牛11");
  }
}

<form action="Test1.ashx" method="post">
<input type="text" name="name" />
<input type="text" name="age" />
<input type="submit" />
</form>
1.post获取方法,获取通过报文体传输的参数post(get获取不到,为NULL):
注意:请求获取的参数都是字符串
string name = context.Request.Form["name"];
string age = context.Request.Form["age"];
2.get获取方法,则通过QueryString获取(post获取不到,为NULL):
string name = context.Request.QueryString["name"];
string age = context.Request.QueryString["age"];
3.不管是post还是get都可获取:
string name = context.Request["name"];
string age = context.Request["age"];
注意:当用get或post方法获取不到值时,string类型返回的是null,int类型返回的是0

ASP.Net核心对象HttpRequest

原文:http://www.cnblogs.com/genesis/p/4661972.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!