HTTP Handler (2)-passing parameters to the HTTP Handler

Source: Internet
Author: User
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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.