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.