Last post Jun 11, 2012 10:57 PM by BrockAllen
Jun 11, 2012 09:58 PM|magicmike2011|LINK
I have an HttpModule I'm building as an assembly. It will be included in multiple different web applications and I would like to implement the ability to provide a "default" static html page (.htm) file that could be served in response to certain page requests.
Basically I would like this implementation to be able to return the static html page from the referenced assembly within the request handler. Essentially it should act like a normal response.redirect.
Is this possible? And if so, how do I go about doing so? I don't want it to act in a way that the user "downloads the page like a file download, but rather, that it would just display in the browser window like a normal page request.
Jun 11, 2012 10:34 PM|BrockAllen|LINK
Your module can bundle the static html as an embedded resource into the assembly and then you can simply open that and stream it to the response. Something like this (pseudocode):
Assembly a = typeof(YourModule).Assembly;
using (var stream = a.GetManifestResourceStream("YourNamespace.YourFile.htm"))
HttpContext.Response.ContentType = "text/html";
Jun 11, 2012 10:50 PM|magicmike2011|LINK
You are soooo going on my friends list Brock!!! lol Thank you again. One question though, if I want this page to override whatever page was originally requested, do I have to do a context.response.ClearContent() before copying the file to the response? Or
should it overwrite it automatically?
Jun 11, 2012 10:57 PM|BrockAllen|LINK
Oh right, yes -- you'd also need a Response.End() in there, and maybe a Response.Clear() before (to remove anything else that might have already been written, yes).