Some time ago, I published an asp.net survival html cache. To be honest, there were a lot of people who had a lot of bugs. After this period of testing and improvement, we should be able to use it,
You are welcome to test and use it. Next I will introduce the tutorial. By the way, I would like to thank monkey for helping me test a lot.
Add a reference to StaticHtml. dll or copy it to the bin directory. The configuration instructions are as follows:
Note: The following configuration steps are all performed in web. config.
1. Add a StaticHtml configuration file read Node
Add the following nodes in configuration/configSections:
<Section name = "staticHtml" type = "StaticHtml. StaticHtmlSection, StaticHtml"/>
Add StaticHtml
2. Add HttpModule
In configuration/system. web/httpModules, add
<Add name = "staticHtml" type = "StaticHtml. HttpModule, StaticHtml"/>
If this configuration is used, use a browser to upload any page. If the file statichtml_log.txt is not generated in the root directory, add the above node to configuration/system. webServer/httpModule.
Of course, make sure that your server can load httpmodule correctlyBecause it is possible that your server configuration cannot load any httpmodule at all.. See asp.net mvcConfiguration
3. Configure cache generation rules for your site
Add the following nodes to configuration:
<StaticHtml skip = "admin/" run = "on">
<Rule name = "index">
<Patten type = "StaticHtml. RegexPatten, StaticHtml" pars = "RegPatten = index \. aspx"/>
<Store type = "StaticHtml. MemStore, StaticHtml"/>
<GenKey type = "StaticHtml. UrlMd5GenKey, StaticHtml"/>
<Expire type = "StaticHtml. TimeExpire, StaticHtml" pars = "Second = 300"/>
</Rule>
<Rule name = "content">
<Patten type = "StaticHtml. RegexPatten, StaticHtml" pars = "RegPatten = article/"/>
<Store type = "StaticHtml. FileStore, StaticHtml" pars = "Path = cacheHtml_article/"/>
</Rule>
</StaticHtml>
The preceding configuration defines two rules,
The first rule,
<Rule name = "index">
<Patten type = "StaticHtml. RegexPatten, StaticHtml" pars = "RegPatten = index \. aspx"/>
<Store type = "StaticHtml. MemStore, StaticHtml"/>
</Rule>
Rule. The name of this rule is index,
If the regular expression index \. aspx is matched in the url of the patten node, It is cached.
The store node saves the cached html to the memory.
The genKey node uses md5 encryption to generate a key for request. rawRul. It is very important in statichtml and represents a unique cache page,
Expire node means 300 seconds of cache (5 minutes)
Second rule
<Rule name = "content">
<Patten type = "StaticHtml. RegexPatten, StaticHtml" pars = "RegPatten = article/"/>
<Store type = "StaticHtml. FileStore, StaticHtml" pars = "Path = cacheHtml_article/"/>
</Rule>
The rule name is content (the rule name cannot be repeated)
If the url matches the regular expression article /,
The store node saves the cached data to/cacheHtml_article in the root directory.
The StaticHtml node skip attribute admin/indicates that if the url matches this regular expression, it is not cached.
Tip: The skip attribute of the staticHtml node and the pars attribute of the patten node can be configured with a regular expression. It is a pure regular expression, which can be complex or simple to write.
4. other supplements
1: The next article will detail how to expand statichtml
2: Download statichtml. dll (the latest version uses gzip to compress the storage, greatly reducing disk usage and website traffic .)
3: source code is still on github https://github.com/tianqiq/StaticHtml
Now the blank space has been fixed after refresh of more than 4.0. You are welcome to test and use it. )
The Code has been updated to github, please download the latest dll http://url.cn/H5TSeH from here