The following is the implementation Code :
/// <Summary>
/// Save the object
/// </Summary>
/// <Param name = "Uri"> request address </param>
/// <Param name = "querystring"> query string </param>
/// <Param name = "targetfilepath"> path of the saved file </param>
Public static void savepage (system. Uri, string querystring, string targetfilepath)
{
// Stream used to save the file
System. Io. filestream stream = NULL;
// Used to save the written object
System. Io. textwriter writer = NULL;
Try
{
// Create an HTTP request
Httprequest request = new httprequest (URI. absolutepath, Uri. absoluteuri, querystring );
// Create a saved file stream
Stream = new system. Io. filestream (targetfilepath, system. Io. filemode. Create );
// Create a file write object
Writer = new system. Io. streamwriter (stream, system. Text. utf8encoding. utf8 );
// Create HTTP feedback
Httpresponse response = new httpresponse (writer );
// Create an HTTP Context
Httpcontext context = new httpcontext (request, response );
// Add a session
Context. Items. Add ("aspsession", httpcontext. Current. session );
// Create a page Analyzer
System. Web. ihttphandler handler = system. Web. UI. pageparser. getcompiledpageinstance (URI. absolutepath,
Httpcontext. Current. server. mappath (URI. absolutepath), context );
// Execute the request
Handler. processrequest (context );
// Write information
Writer. Flush ();
// close
writer. close ();
}< br> finally
{< br> // close the writer
If (null! = Writer)
{< br> writer. Dispose ();
}
// close the stream
If (null! = Stream)
{< br> // close
stream. dispose ();
}< BR >}< br> note the transfer of session. If the session is not passed, the session-related data cannot be obtained.