How to save an ASP. NET page as an HTML file

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.