.net一般应用处理程序

来源:互联网 发布:mac 储存 应用 编辑:程序博客网 时间:2024/05/22 00:14

.net一般应用处理程序

public void ProcessRequest (HttpContext context) {    context.Response.ContentType = "text/html";    //1.获取请求的数据(get提交方式)标签的name就是“key”    int age = Convert.ToInt32(context.Request.QueryString["txtAge"]);    //context.Request.Form["key"](获取post请求的数据)    //context.Request.Params["key"](post和get都能获取到,但效率低些)  //  context.Request["key"](都能获取到)    context.Response.Redirect("");//重新定向到新的地址    age++;    //返回数据   string html=  File.ReadAllText(context.Request.MapPath("IncAge.htm"));//将虚拟路径转换成绝对路径,ReadAllText只能读取绝对路径的文件   html = html.Replace("<input type=\"text\" name=\"txtAge\" value=\"\" />", "<input type=\"text\" name=\"txtAge\" value=\"" + age + "\" />");    替换操作时。可在前台页面设置一个有标志的变量如:@name,替换时只需要replace(@name,值)就可以        context.Response.Write(html);}

form表单提交

<form action="IncAge.ashx" method="get"><input type="text" name="txtAge" value="" /><input type="submit" name="name" value="增长" /></form>

action指向后台路径,注意:Get请求方式不安全,参数会在Url中以明文显示出来(浏览器的地址栏可以看到)
登录、注册等信息一般采用post方式

0 0
原创粉丝点击