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>
后端
string str="用户名:"+context.Request.Form["user"];
3.get post 都可以获取
string str=HttpContext.Current.Request["user"];