欢迎访问我的博客 https://javascript.shop

ashx接收参数 ashx传递参数

原文发布时间为:2009-09-30 —— 来源于本人的百度文章 [由搬家工具导入]

Handler.ashx文件:

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data;
public class Handler : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
        string strSql = "Select IP from Web where _D="+context.Request.QueryString["id"];
        DataUtility objData = new DataUtility();
        DataSet dstList = objData.QueryData(strSql);
        context.Response.ContentType = "text/plain";
        context.Response.Write("document.write(\"" + dstList.Tables[0].Rows[0][0].ToString() + "\")");
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

html或者 aspx文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript" src="/ajax/AjaxHandler"></script>
    <title>无标题页</title>
</head>
<body>
<script type="text/javascript" src="Handler.ashx?id=2"></script>
</body>
</html>

输出结果为 ID为2的 IP

posted @ 2017-07-13 00:12  孑孓子  阅读(1555)  评论(0编辑  收藏  举报
欢迎访问我的博客 https://javascript.shop