我自己做了一个类实现了IHttpHandler和IRequiresSesssionState接口:public class MyHttpHandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
usingCount++;
context.Response.Write(context.Request["ParamThroughGet"]);
context.Response.Write(context.Request["ParamThroughPost"]);
context.Response.End();
} public bool IsReusable
{
get
{
return true;
}
}
}web.config中配置如下:
<httpHandlers>
<add verb="*" path="*.agt" type="Trying.MyHttpHandler, MyHttpHandler" />
</httpHandlers>在IIS中加入了文件类型*.agt,指定允许包括GET,POST在内的所有方法,并映射到aspnet_isapi.dll进行处理。客户端页面作了一个静态html进行测试
<html>
<body>
<form id="Form1" method="post" action="test.agt?ParamThroughGet=123">
<input id="ParamThroughPost" type="text">
<input id="Ok" type="submit">
</form>
</body>
</html>结果是:
对于用GET方法提交的参数,MyHttpHandler可以得到参数值(ParamThroughGet),但对于POST方法提交的form中的数据,就得不到了,总是返回null。
请高人指点一下,这是为什么。
谢谢了
{
public void ProcessRequest(HttpContext context)
{
usingCount++;
context.Response.Write(context.Request["ParamThroughGet"]);
context.Response.Write(context.Request["ParamThroughPost"]);
context.Response.End();
} public bool IsReusable
{
get
{
return true;
}
}
}web.config中配置如下:
<httpHandlers>
<add verb="*" path="*.agt" type="Trying.MyHttpHandler, MyHttpHandler" />
</httpHandlers>在IIS中加入了文件类型*.agt,指定允许包括GET,POST在内的所有方法,并映射到aspnet_isapi.dll进行处理。客户端页面作了一个静态html进行测试
<html>
<body>
<form id="Form1" method="post" action="test.agt?ParamThroughGet=123">
<input id="ParamThroughPost" type="text">
<input id="Ok" type="submit">
</form>
</body>
</html>结果是:
对于用GET方法提交的参数,MyHttpHandler可以得到参数值(ParamThroughGet),但对于POST方法提交的form中的数据,就得不到了,总是返回null。
请高人指点一下,这是为什么。
谢谢了
context.Response.Write(context.Request["ParamThroughGet"]);
else
if(context.Request.HttpMethod.ToLower()=="post")
context.Response.Write(new StreamReader(context.request.InputStream).ReadToEnd());