Add a file of type "generic handler". You can send back any kind of
content you want by providing the correct HTTP header information via
Response.Write statements. Code should look something like this:
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
Random r = new Random();
public void ProcessRequest (HttpContext context) {
String myParam = context.Request .Params.Get("cl ientkey");
int numstrings = myProverbs.Leng th;
int myRandIndex = r.Next(numstrin gs);
String answer = myProverbs[myRandIndex];
context.Respons e.ContentType = "text/xml";
context.Respons e.AddHeader("Ca che-Control", "no-cache");
context.Respons e.Write("<?xml version=\"1.0\" ?>");
context.Respons e.Write("<stuff >");
context.Respons e.Write("<quote >" + answer + "</quote>");
context.Respons e.Write("<clien tkey>" + myParam + "</
clientkey>");
context.Respons e.Write("</stuff>");
}
public bool IsReusable {
get {
return false;
}
}
String[] myProverbs = {
/* 0 */ "I am prepared for the worst, but hope for the best.
(Benjamin Disraeli)",
/* 1 */ "Lost time is never found again. (Ben Franklin)",
/* 2 */ "History is a pack of lies about events that never happened
told by people who weren't there. (George Santayana)",
/* 3 */ "Tact is the ability to describe others as they see
themselves. (Abe Lincoln)",
/* 4 */ "Always remember, a cat looks down on man, a dog looks up to
man, but a pig will look man right in the eye and see his equal.
(Winston Churchill)",
/* 5 */ "What's left at the bottom of the bag when it reaches you.
(Definition of microchips)",
};
}
On Oct 9, 4:31 pm, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yohohhoandabo ttleofrum.comwr ote:
You have to have an Http - addressable endpoint. It could be an ASPX page, or
it could be an ASHX handler, etc. For a page, the only requirement is to have
the
<@Page declaration and specify the codebehind / codefile attribute. What you
do in your code is completely up to you.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
"Frankie" wrote:
What would it take to send a page to a browser - and the HTML that comprises
that "page" is 100% generated dynamically?
Specifically, say I have all of the requisite HTML in a string variable. How
do I push that string down to the browser?
My situation is that I have a few .aspx pages containing very little
boilerplate HTML markup and several placeholder controls. At runtime I am
currently injecting the requisite HTML into the placeholder controls. I am
wondering what it would take to eliminate the .aspx file altogether... such
that when the browser requests, for example,
www.DomainName\SomeFolder\File001.aspx I have logic that returns 100% of the
HTML of "File001.as px" with no such .aspx file having ever existed on disk
on the Web server.
Thanks.