In the previous article, we created the simplest HTTP handler "MyHandler. "jxd", now let's make a slight modification to her, so that she can receive a parameter and directly return this parameter value.
Step 1: Modify MyHandler. cs to let her return the received parameter value. MyHandler. cs
Using System;
Using System. Collections. Generic;
Using System. Text;
Namespace mylib. system. web
{
Public class MyHandler: System. Web. IHttpHandler
{
# Region IHttpHandler Member
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 ("}
# Endregion
}
}
Step 2: Modify Default. aspx so that IFrame can pass a parameter to 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> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Iframe src = '~ /MyHandler. jxd? N = impossible is nothing '> </iframe>
</Div>
</Form>
</Body>
</Html>
Step 3: Set Default. aspx as the start page and press F5 to run the program.
Download all source code in this article
This article ends here, and we will make a little practical.
6 articles in this series
Practical HTTP Handler (HTTP Handler) (6) -- random bar code
Actual HTTP Handler (HTTP Handler) (5) -- directly open the dynamically generated file without using temporary files
Practice HTTP Handler (4) -- share Session with Web programs
HTTP Handler (3) -- dynamically generate images
HTTP Handler (2) -- passing parameters to the HTTP Handler<-You are here.
HTTP Handler (1) -- create the simplest HTTP Handler