1. 程式人生 > >ashx接收參數 ashx傳遞參數

ashx接收參數 ashx傳遞參數

bold ssr 接收 head text sys public ef6 src

原文發布時間為: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

ashx接收參數 ashx傳遞參數