Core tips:On the Internet, you will often see that the address suffixes of many websites use XX. HTML or XX. ASPX and other operations are similar to static file identifiers. have you ever wondered whether it is actually a static file generated one by one? What are the advantages and disadvantages of static file generation, for websites with a large access volume, using static files can improve the stability and speed of server operation...
On the Internet, you will often see that the address suffixes of many websites use XX. HTML or XX. ASPX and other operations are similar to static file identifiers. have you ever wondered whether it is actually a static file generated one by one? What are the advantages and disadvantages of static file generation, for websites with a large volume of traffic, using static files can improve the stability and speed of the server. The disadvantage is that when a list is generated, a record is added and all related lists need to be reconstructed, of course, it is not ruled out that some companies have overcome this problem, but it is still a problem for mass programmers, and the generated version is not necessarily more dynamic than the small and medium websites, this is because management is troublesome.
Structure of the above facts, followed by pseudo-static technology, the standard is URL rewriting technology, he has the best support for the ASPX format, of course, can also rewrite HTML files, however, this requires the setting of IIS, which is more convenient than the ASPX format. This site uses the URL rewriting technology. This technology has obvious advantages: it is convenient for search engines to include and view, and so on. Then let's take a look at how to configure him.
First, you need to reference two DLL files in your project:
URLRewriter. dll
ActionlessForm. dll
The actual rewrite is URLRewriter. dll. But if you want to implement paging, you must use this ActionlessForm. dll
Http://www.microsoft.com/web/spotlight/urlrewriter/
Http://urlrewriter.net/
2. Configure the WEB. CONFIG file
Reference this Assembly in the project. The pseudo-static syntax is... (for example, the. aspx page is represented in .html. In the web. config file, --> Add the following nodes.
<Configuration> <configSections> <section name = "RewriterConfig" requirePermission = "false" type = "URLRewriter. config. rewriterConfigSerializerSectionHandler, URLRewriter "/> </configSections> <RewriterConfig> <Rules> <RewriterRule> <! -- A parameter-> <LookFor> ~ /Cn/ss _ (. [\ d] *) \. html </LookFor> <SendTo> ~ /Cn/news. aspx? Id = $1 </SendTo> </RewriterRule> <! -- Upload two parameters --> <LookFor> ~ /Cn/ss _ (. [\ d] *) 0 (. [\ w] * ).html </LookFor> <! --(. [\ D] *) (. [\ w] * ).html or ss _,(. [0-9] *), (. [0-9] *) \. html --> <SendTo> <! [CDATA [~ /Cn/news. aspx? Id = $1 & sid = $2]> </SendTo> </RewriterRule> <! -- Three parameters --> <LookFor> ~ /Cn/ss _ (. [\ d] *) 0 (. [\ w] *) 0 (. [\ w] * ).html </LookFor> <SendTo> <! [CDATA [~ /ZH-CN/news. aspx? Id = $1 & sid = $2 & n_id = $3]> </SendTo> </RewriterRule> <LookFor> ~ /Dfsaddf/index (\ d *) \. html </LookFor> <SendTo> ~ /Favorites_Page.aspx </SendTo> </RewriterRule> </Rules> </RewriterConfig> <system. web> </Configuration>
After setting the preceding steps, you can basically run it. The <RewriterRule/> label contains a rewritten module, and the <LookFor/> label contains the rewritten address, <SendTo/> is the original address.3. Configure the iis .html File
Configure IIS6.0
IIS configuration: website-> properties-> virtual directory-> Configuration (G)...-> ing-> wildcard application ing-> Add
Executable File: c: \ windows \ microsoft.net \ framework \ v2.0.50727 \ aspnet_isapi.dll
Extension:. html
Check whether the file exists: No.
Configure IIS7.5
Your website --> handler ing in IIS -->
Add script ing (Path: *. html Executable File % windir % \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_isapi.dll name: arbitrary, such as Hml)
Add wildcard script ing (Path: * Executable File: C: \ Windows \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_isapi.dll name: arbitrary, such as All)
Managed handler ing (Path: * Executable File: System. Web. UI. PageHandlerFactory name, for example, Html-Integrate) -------->
Module in IIS --> Add ----> (Name: any type such as All: URLRewriter. ModuleRewriter hooks OK for sending requests only to the asp.net application or managed handler)
--> OK
4. After the above configuration is complete, you can access it through the following methods:
For example, if you enter hostname/d11.html,
The server will rewrite it to http: // hostname/default. aspx? Id = 11.
In other words, the user enters http: // hostname/d11.html,
Actually accessed is http: // hostname/default. aspx? Id = 11
ActionlessForm. dll
namespace ActionlessForm { public class Form : System.Web.UI.HtmlControls.HtmlForm { protected override void RenderAttributes(HtmlTextWriter writer) { writer.WriteAttribute("name", this.Name); base.Attributes.Remove("name"); writer.WriteAttribute("method", this.Method); base.Attributes.Remove("method"); this.Attributes.Render(writer); base.Attributes.Remove("action"); if (base.ID != null) writer.WriteAttribute("id", base.ClientID); } } }
After creating and compiling this class, you must first add it to the References folder of the Web application to use it in the ASP. NET Web application. Then, you need to use it to replace the HtmlForm class. The practice is in ASP. add the following content to the top of the web page: <% @ Register TagPrefix = "skm" Namespace = "ActionlessForm" Assembly = "ActionlessForm" %> then, replace <form runat = "server"> (if any) with: <skm: form id = "Form1" method = "post" runat = "server"> and replace the </form> mark on the right:
</Skm: Form> successful!
Note that if you want to access http: // domain name/C/303/168 .html and access http: // domain name/C/303/168 .htm both to access the same actual address, no prompt is displayed. You need to add the following code between the
You should also pay attention to adding hyperlinks to the page, and the hyperlinks should be changed according to the configuration.
<A href = "<% = ResolveUrl (" index.html ") %>"> homepage </a> (default. aspx is actually accessed)
<A href = "<% = ResolveUrl (" I/158.html ") %>"> News </a> (the actual access is InfoList. aspx? Id = 158)
<A href = "<% = ResolveUrl (" C/378.html ") %>" About Us </a> (actually accessing Content. aspx? Id = 378)
<A href = "<% = ResolveUrl (" C/381/167 .html ") %>"> O, Yeah! </A> (the actual access is Content. aspx? Id = 381 & Catalogid = 167)
For the resources requested by the server control, you can use "~ /File path and file name ". The preceding method can be used for HTML controls and elements.
5. Solve the Problem of true path reproduction after sending back
(You can add a Button on the page and click "try" after running)
1. Add ActionlessForm. dll to the bin folder of the project.
2. Add <% @ Register TagPrefix = "RW" Namespace = "ActionlessForm" Assembly = "ActionlessForm" %> in the code of the aspx webpage (load the next line of the Page command)
3. Change the form label to RW: Form (you must change both the start and end). You can customize the TagPrefix.