一般处理程序

    public class TestHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello World");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
            //相对路径转为绝对路径
            string path = context.Request.MapPath("/TestHandle.ashx");
            context.Response.Write(path);

 请求

 1.获取get表单传递到ashx的值

    <form action="TestHandler.ashx" method="get">
        <input type="text" name="user" />
        <input type="password" name="pw" />
        <input type="submit" />
    </form>
string str= context.Request.QueryString["user"];

2.post请求

    <form action="TestHandler.ashx" method="post">
        <input type="text" name="user" />
        <input type="password" name="pw" />
        <input type="submit" />
    </form>

后端

扫描二维码关注公众号,回复: 2832345 查看本文章
string str="用户名:"+context.Request.Form["user"];

3.get post 都可以获取

string str=HttpContext.Current.Request["user"];

猜你喜欢

转载自www.cnblogs.com/buchizaodian/p/9496184.html