您的位置:首页 > 理论基础 > 计算机网络

实战 HTTP 处理程序(HTTP Handler) (2) -- 向HTTP 处理程序传递参数

2007-10-23 21:36 495 查看
实战 HTTP 处理程序(HTTP Handler) (2) -- 向HTTP 处理程序传递参数
我们在上一篇已经创建了一个最简单的HTTP 处理程序“MyHandler.jxd”,现在我们来对她稍作修改,让她可以接收一个参数并直接返回这个参数值。
Step1:修改 MyHandler.cs,让她返回接收到的参数值。




MyHandler.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace mylib.system.web
{
public class MyHandler : System.Web.IHttpHandler
{
#region IHttpHandler 成员

public bool IsReusable
{
get { return false; }
}

public void ProcessRequest(System.Web.HttpContext context)
{
string n = context.Request.QueryString["n"];

context.Response.ContentType = "text/html";
context.Response.Write("<html><body>" + n + "</body></html>");
}

#endregion
}
}

Step2:修改 Default.aspx ,让 IFrame 向 MyHandler.jxd 传递一个参数。




Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<iframe src='~/MyHandler.jxd?n=impossible is nothing'></iframe>
</div>
</form>
</body>
</html>

Step3:将 Default.aspx 设为起始页,按F5运行程序。



下载本篇全部源代码

本篇到此结束,下一篇我们将作个稍微实用一点的东西。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐