An idea of HTML-based Asp.net applications

Source: Internet
Author: User
A slightly larger website will cache the pages of Asp.net. When users access the page, they first check whether the corresponding HTML file exists and generate the file once if it does not exist. Or simply use Asp.net as the background program. The whole site HTML file generated by the background program is provided only in HTML format to the viewer. The latter is a self-built system with better efficiency than the former, but it is much more complicated than the former. It is not something I can say in three or two words. I just want, is there a simple HTML Method for Asp.net programs in the former?

Adds an httpmodule to an Asp.net program and makes a small attempt.

<Httpmodules>
<Add name = "myhtmlmodule" type = "modulelib. myhtmlmodule, modulelib"/>
</Httpmodules>

Myhtmlmodule. CS is simple. It implements the ihttpmodule interface.

Public void Init (httpapplication context)
{
// Todo: Add htmlmodule. init to implement
Context. beginrequest + = new eventhandler (context_beginrequest );
}

Private void context_beginrequest (Object sender, eventargs E)
{
Httpapplication application = (httpapplication) sender;
Httpcontext context = application. context;
Switch (context. Request. Path)
{
Case "/httpmoduletest/htmlpage. aspx? Page = 1 ":
Context. rewritepath ("htmlpage_page_1.htm ");
Break;
Case "/httpmoduletest/htmlpage. aspx? Page = 2 ":
Context. rewritepath ("htmlpage_page_2.htm ");
Break;
}
}

The above context_beginrequest method is very stupid, just for testing, it is easy to use a regular expression to match the aspx <=> HTML name.

The test basically proves that the idea works. "Htmlpage. aspx" in the test project has never been executed, and the two HTML files appear on ie as scheduled.

In actual applications, use a regular expression to obtain the corresponding HTML file name and check whether HTML exists or does not exist. Access the aspx file and save the generated content. Of course, it is easy to do so, directly rewritepath (HTML ).

Efficiency naturally cannot be compared with the pure HTML website generated by Asp.net.

Related Article

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.