I am trying to use the ASP.NET (3.5) "Routing Module" functionality to create custom pages based on the contents of the URL.
Various articles explain how to use ASP.NET Routing to branch to existing pages on the web server.
What I would like to do is create the page on-the-fly using code.
My first attempt looks like this:
public class SimpleRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
string pageName = requestContext.RouteData.GetRequiredString("PageName");
Page myPage = new Page();
myPage.Response.Write("hello " + pageName);
return myPage;
}
}
But this throws an HTTPException saying "Response is not available in this context." at the Response.Write statement.
How to proceed?
UPDATE: In the end, I went with an approach based on IHttpModule, which turned out to be rather easy.