Is it possible to run an aspx file in background as "In memory" operation

836 Views Asked by At

I have an physically existing aspx file on IIS. It has a asp.net Grid View controls and few lines of html.

Now what I want is , the code will render the aspx somewhere in memory with the grid view populated with database in runtime. Then through my code , i will be able to read the entire generated html.

Is it possible? Or any alternative so that I can open the form but it will be not availabe to the user, some kind of visible=false thingy.

Kindly help.

Note:

I am expecting same process as we use to read txt files. But here i need one more extra stuffing, that is ,calling the page life cycle events too.

2

There are 2 best solutions below

9
On

You could use the RenderControl method to output a control to an HtmlTextWriter object.

using (var textWriter = new StringWriter())
using (var writer = new HtmlTextWriter(textWriter))
{
    yourControl.RenderControl(writer);
    var html = textWriter.ToString();
}
0
On

The scenario you are describing is not a very good one, from the design prospective. I must make clear that I would never suggest it, under normal circumstances. I suppose you have a very good reason you have to use this "hidden" page.

So this is my "suggestion". You could host the "hidden" aspx in a seperate web application in another process, not accessible from outside your server. Then, your normal asp.net application could make an HTTP request on code behind, targeting the "hidden" page and using the response (parsing the HTTP response using a tool like HTML Agility. You could hide the specific page by putting it on another site in IIS and secure it through a firewall rule. I am sure there are other ways to hide it too, but this is an easy way to go.

Hope I helped!