public void getContent() {
string VirtualPath = "~/Content.aspx";
var page = BuildManager.CreateInstanceFromVirtualPath( VirtualPath, typeof( Page ) ) as IHttpHandler;
page.ProcessRequest( HttpContext.Current );
}
I'm using that function to load the content from different files, but the "page.ProcessRequest( HttpContext.Current )" inserts the content at the current context, and what I need is the function to return the content of the specified file.
I wonder if there's a working way to create a new HttpContext, so that "page.ProcessRequest" don't insert anything into the current response.
Oded is correct as far as I know. You can't easily create your own instance of the HttpContext. However you can still achieve your goals thorugh other means.
Use a Server.Execute. http://msdn.microsoft.com/en-us/library/ms150027.aspx.
You can specify the HttpHandler to execute along with a TextWriter to dump the content into.
You can't create a new HttpContext
, not without lots of work arounds.
It is one of the failings of ASP.NET and the BCL - makes web applications untestable (or at least very difficult to test without HttpContext
.
I am not clear on your requirement what I need is the function to return the content of the specified file
- can you please explain exactly what you mean by that?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With