如何获取HttpContext context的值

windily 2007-06-26 11:38:51
在客户端xmlhttprequest.send(name)到服务器,如何通过HttpContext context获取name的值,请各位大侠告知.
如果用string name = context.Request.Form[1].ToString();
会显示错误,
索引超出范围。必须为非负值并小于集合大小。
参数名: index
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index
不知道什么问题
...全文
2153 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ivony 2007-06-27
  • 打赏
  • 举报
回复
楼主是否知道数组下标从0开始?
windily 2007-06-27
  • 打赏
  • 举报
回复
高手解答下了
windily 2007-06-27
  • 打赏
  • 举报
回复
windily 2007-06-27
  • 打赏
  • 举报
回复
上面的应该是简化成这样的
public class IsHave : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
String[] kk=context.Request.Form.AllKeys;
string name=kk[0];//改为name=context.Request.Form.GetKey(0);也不行
if (kk.Length >0)
{
if (name.length>0)
context.Response.Write(name);
}
}
windily 2007-06-27
  • 打赏
  • 举报
回复
上面的程序中if (name.length>0)
context.Response.Write(name);是没有执行到的,究竟为什么会这样
windily 2007-06-27
  • 打赏
  • 举报
回复
还是不行,我的程序如下,帮我看看
function Button2_onclick() {
var name=document.getElementById("u_name").value;
XmlHttpRequest=new ActiveXObject("Msxml2.XMLHTTP");
XmlHttpRequest.open("POST","IsHave.ashx",true);
XmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
XmlHttpRequest.send("hhh");
XmlHttpRequest.onreadystatechange=response_data;
}
function response_data()
{
if(XmlHttpRequest.readyState==4)
{alert("222");
if(XmlHttpRequest.status==200)
{
alert("111");
alert(XmlHttpRequest.responseText);
if(XmlHttpRequest.responseText=="插入成功")
{
window.opener='_self';
window.close();
}
}
}
}
public class IsHave : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
String[] kk=context.Request.Form.AllKeys;
name=kk[0];//改为name=context.Request.Form.GetKey(0);也不行
if (kk.Length >0)
{
if (name.length>0)
context.Response.Write(name);
}
string name = kk[0]; //context.Response.Write(name.Length);
if (name!= "77")
{
context.Response.Write("aaaaaaaaaa");
}
context.Response.Write(UserInfoAccess.GetAccess.isHave(name));
}
Ivony 2007-06-27
  • 打赏
  • 举报
回复
GetKey
windily 2007-06-27
  • 打赏
  • 举报
回复
利用string[] nn = context.Request.Form.allkeys;
可以得到nn.length=1;
可是用 response.write(nn[0].length);没显示到什么
windily 2007-06-27
  • 打赏
  • 举报
回复
我是从0开始的,上面写错了

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧