ASP. NET pseudo-static explanation and configuration, asp.net pseudo explanation

Source: Internet
Author: User
Tags xml cdata

ASP. NET pseudo-static explanation and configuration, asp.net pseudo explanation

Directory:

1. What is pseudo-static

Ii. Why do we need to make the website pseudo-static?

III,HowASP. NETConfigure pseudo-static(If you know the first two items, you can start with the third item)

4. Related Knowledge

V. References

 

1. What is pseudo-static

 

Definition: dynamic web pages remove the parameters of dynamic web pages by rewriting URLs, but there is no need to rewrite pages in the actual web directory.

 

For example, what is the access address? Year = 2012 & month = 06 & day = 05 & id = 2529259.

 

Ii. Why do we need to make the website pseudo-static?

 

1. Use of pseudo-static

 

Some users think that the amount of pseudo-static and real-static files actually indexed is quite different. Otherwise, from your personal perspective, do you determine whether a post is real static or pseudo-static? It is hard to see, because the so-called static means that the address does not contain question marks, but static means. Is it true or false? Can the search engine see it? Therefore, whether it is true or false, it is the same for the search engine. The search engine did not say that you are false. I will not include you.

 

Why does the search engine not include websites with question marks? Because the search engine is afraid of entering an endless loop due to question marks, it is called "Spidertraps" (in the past, there was such a vulnerability on the mobile network, and the Spidertraps came in ), therefore, the address search engine with question marks is not used in many cases. pseudo-static search engines are actually static because the address does not contain question marks, therefore, there is no more true or static data than pseudo static data.

 

2. Why do I select pseudo static?

 

Many users say: Is it really static? Why not use static data? Isn't access faster? Isn't the load better? Wait ......

 

Here, we only use one question to answer: Why MYSQL? Many users may not understand why MYSQL databases have been used as a storage mechanism in many large forums. Most of them all think about it: "Because DZ uses MYSQL, It is MYSQL ".

 

In fact, why did DZ survive on the days when so many Forum programs coexist? A major reason is that DZ uses MYSQL. imagine if the program modified by Big C was a text forum, would there be a DZ today? Or from another perspective, why do so many large websites choose MYSQL instead of text as the storage mechanism?

 

The so-called text forum is similar to the real static statement. It stores data in space, reads and writes a large number of hard disks, and so on ......

 

Why is this writing method obsolete? I believe the answer is not what the teacher said: "Discuz! There are currently 2129867 posts, and the size of html stored is about 20799 MB, that is, about 20 GB. This does not calculate the space waste caused by the disk storage mechanism (the space occupied by 100 1 K files may be 200 K ). "

 

From my personal point of view, this reason cannot be used by users for reasons that are not true or static. However, another reason is worth thinking about, that is why most sites do not choose to generate static data:

 

"Deleting and updating these html content will lead to a large number of disk io operations and a large number of disk fragments. "

 

As mentioned above, in practice, a large number of disk I/O operations (input/output) and a large number of I/O operations can be imagined, A large number of disk fragments may even cause bad sectors on the hard disk.

 

Therefore, for static generation, it is better to use text forums to better address your needs. (Vice W was born from a text Forum. At that time, the name was ofstar, which was converted to MYSQL due to development difficulties, PW generates static pages, that is, the original PW text method, which is slightly improved to attract users' attention)

 

Of course, if you have a good memory, you can remember that during PW4, the PW forum could not be accessed for a long time, and the data was recovered some time ago, the official statement is that the hard disk is damaged due to attacks. In fact, this statement is not credible. As a result, the hard disk is damaged due to attacks or a large number of I/O operations, I personally prefer the latter.

 

Of course, if you are more concerned about 5d6d, you should know that 5d6d was inaccessible one day a few days ago. According to unofficial news, the hard disk was broken, the reason for the damage is that a large number of users perform a large number of I/O operations. Imagine that in our forum, disk I/O operations are performed only when the administrator updates the cache, every member in 5d6d is an administrator. How big is the test of the disk? So I am not surprised that the 5d6d hard disk is broken.

 

Of course, many of my friends who have been reading this article have used BT, and I have heard that BT is very harmful to hard disks and cannot be opened. The so-called damage is the same as what we refer to here, A large number of I/O results in disk fragments and even bad sectors.

 

Here are some practical examples to illustrate the problem.

 

3. disadvantages of pseudo-static

 

Of course, as the author of an article said: "if the traffic is slightly larger, the use of pseudo-static resources will overload the CPU usage, and more than 300 concurrent online users will be suspended, when no pseudo-static data is used, more than 500 online users will not be suspended at the same time. My ISS count is 1000."

 

This is true. Because the pseudo-static mode uses regular expressions instead of real addresses, the responsibility for determining which page is displayed is determined by the CPU directly. Therefore, the CPU usage increases, it is indeed the biggest drawback of pseudo-static.

 

4. Should we choose pseudo static or real static?

 

Let's summarize:

 

(1) There is no difference between real static and false static for SEO.

 

(2) using static data may cause damage to the hard disk and affect Forum performance.

 

(3) The use of pseudo-static will occupy a certain amount of CPU share, a large number of use will lead to CPU overload

 

(4) The most important thing is that we need static resources for SEO.

 

Therefore:

 

(1) The use of real static methods can be ruled out directly, because no matter how it is generated, it is very bad for the hard disk.

 

(2) Since the authenticity and static effect are the same, we can choose pseudo static.

 

(3) but the excessive use of pseudo-static resources will result in CPU overload.

 

(4). We only need to use it in large quantities.

 

(5) Since static data is only for SEO, we only need to give it to SEO with pseudo static data and do not need it for users.

 

(6) so we only need to use pseudo static data in the Archiver dedicated to SEO crawling.

 

(7) Thank you for your patience in reading my article.

 

(8) Do you have any questions or different opinions.

 

5. Comments on pseudo-static and real-static

 

Real static and pseudo static are essentially different. For browser users to process a pure htm and a php that calls multiple data, the former is significantly less in terms of CPU usage. I remember someone who said that html hard drives were frequently downloaded and read/written. He said that it seems that the database does not need to be read or written to the disk. Besides, there are a lot of scattered php cache files on the hard disk, do these reads require no disk operations? Ridiculous.

 

Read a single htm + image Flash and other attachments, why do I have to read the database, read the php cache file, re-integrate the data output, and add attachments such as image Flash? The CMS homepage does not require a lot of interaction. The forum should not be used here. On the contrary, you should consider more: Beautiful! Compatible! Intuitive information! Performance! Stability!

 

In fact, the so-called pseudo-static page refers to URL rewriting, which is very simple to implement in ASP. NET. First, you need to reference two DLL: ActionlessForm. dll and URLRewriter. dll in your project. The actual rewrite is URLRewriter. dll. But if you want to implement paging, you must use this ActionlessForm. dll.

 

3. HowASP. NETConfigure pseudo-static

 

1: http://download.csdn.net/source/524514
2: http://www.nmju.net/UserFiles/URLRewriter.rar
3: http://download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi

 

URLRewriter. dll

 

1. Download msdnurlrewriting.zip first. Do not download URLRewriter. dll directly on the network. Generally, the URLRewriter. dll on the network is generated only 8 KB without compilation, but the actual size is about 20 kb.

 

2. msdnurlrewriting.zip. msi file, click Install, and you can find URLRewritingCode in the installation file. sln, click open, and then regenerate the solution to obtain the re-generated URLRewriter. dll (20 KB ).

 

3. Copy URLRewriter. dll to the binfile of the project and add references.

 

4. The following is the configuration of the Web. Config file.

 

4. 1. In the web. config file, configure nodes under <configSections> of the <configuration> node

 

<! -- Configure the rewrite rule node -->

<Sectionname = "RewriterConfig" type = "URLRewriter. Config. RewriterConfigSerializerSectionHandler, URLRewriter"/>

 

. Write rewrite rules in the <configuration> node range class

 

1 <! -- Rewrite Rules --> 2 3 <RewriterConfig> 4 5 <RewriterRule> 6 7 <LookFor> ~ /Index.html </LookFor> 8 9 <SendTo> ~ /Index. aspx </SendTo> 10 11 </RewriterRule> 12 13 <RewriterRule> 14 15 <LookFor> ~ /S.html </LookFor> 16 17 <SendTo> ~ /S. aspx </SendTo> 18 19 </RewriterRule> 20 21 <RewriterRule> 22 23 <LookFor> ~ /S/(. [\ w] *)/(. [\ d] * ).html </LookFor> 24 25 <! --(. [\ D] *) (. [\ w] * ).html or ss _,(. [0-9] *), (. [0-9] *) \. html --> 26 27 <SendTo> <! [CDATA [~ /S. aspx? Wd = $1 & type = $2]> </SendTo> 28 29 </RewriterRule> 30 31 <RewriterRule> 32 33 <LookFor> ~ /S/(. [\ w] *)/(. [\ d] *)/(. [\ d] * ).html </LookFor> 34 35 <SendTo> <! [CDATA [~ /S. aspx? Wd = $1 & pn = $2 & type = $3]> </SendTo> 36 37 </RewriterRule> 38 39 </RewriterConfig>

 

. Configure the following in the <system. web> node

 

<Add verb = "*" path = "*. aspx "type =" URLRewriter. rewriterFactoryHandler, URLRewriter "/> <add verb =" * "path = "*. html "type =" URLRewriter. rewriterFactoryHandler, URLRewriter "/> <! -- If this node is not added, html pages cannot be targeted. -->

 

5. Configure the iis .html File

 

Configure IIS6.0IIS

 

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)

 

6. 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 and actually accesses 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, use it to replace the HtmlForm class by adding the following content at the top of the ASP. NET webpage:

 

<% @ Register TagPrefix = "skm" Namespace = "ActionlessForm" Assembly = "ActionlessForm" %> replace <form runat = "server"> (if any): <skm: Form id = "Form1" method = "post" runat = "server"> Replace the </form> tag on the right with: </skm: Form>

 

Successful!

 

Virtual Host

 

We can see on the Internet that many friends use HttpHandle + Server. Transfer to perform urlrewrite in asp.net. In fact, this method is incorrect.

 

First, HttpHandle cannot implement urlrewrite;

 

The second Server. Transfer is a standard redirection, and it is not urlrewrite at all.

 

In fact, you do not need to implement HttpHandle or HttpModule on your own to implement urlrewrite. You can easily implement it with several lines of code. I will introduce that on a VM, the VM is different from its own server. You do not have the permission to modify iis or install iis plug-ins such as iis rewrite. However, we can still easily complete the required functions. The procedure is as follows: open global. asax. cs and locate protected void Application_BeginRequest (Object sender, EventArgs e ). From the method name, I can guess what it is. Enter the following code:

 

    protected void Application_BeginRequest(Object sender, EventArgs e)    {        string oldUrl = HttpContext.Current.Request.RawUrl ;        string pattern = @"^(.+)default/(/d+)/.aspx(/?.*)*$";        string replace = "$1default.aspx?id=$2";        if(Regex.IsMatch(oldUrl, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled))        {            string newUrl = Regex.Replace(oldUrl, pattern, replace, RegexOptions.Compiled | RegexOptions.IgnoreCase);            this.Context.RewritePath(newUrl);        }    }

 

With the above code, I access a code similar :... /default/123. aspx URL, of course, this URL does not exist on my computer, it will be directed :... /default. aspx? Id = 123.

 

Of course, with a powerful regular expression, you can rewrite the url as needed. All of this is done silently on the server side and won't be noticed on the client side. Because it is on the virtual host, we can only redirect the. aspx file. If it is your own server, you only need to register the Suffix in iis to implement any suffix processing. For example, you can register a type such as *. myweb, so that when someone accesses default/456. myweb, You can redirect it to default. aspx? Id = 456. In a word, as long as you can think of it,. net can help you implement it, and it does not require much code.

 

4. Related Knowledge

 

1. Regular Expression

 

There is a classic Tutorial: getting started with regular expression for 30 minutes. You can search for it. This tutorial is indeed very simple. After reading it, there is no problem in writing some simple regular expressions. Regular Expressions are a tool that requires long-term use, so you don't have to forget it for a period of time. So I read this tutorial every time. What is important after learning is that.

 

A simple list is as follows:

 

. All characters other than line breaks

\ W matches letters, numbers, underscores, and Chinese characters

\ S matches any blank space character

\ D matching number

\ B matches the start or end of a word

^ Match the start of a string

$ End of matching string

* Repeated zero or more times

+ Repeat once or more times

? Zero or one repetition

{N} repeated n times

{N,} repeat n times or more times

{N, m} repeat n to m times

 

When the application is replaced, the content matched in the first () is referenced with $1, and the matching content in the second () is referenced with $2 ...... (See Figure 4.2) the stuff in this () is called an atomic group.

 

2. XML CDATA

 

The term CDATA refers to text Data that should not be parsed by the XML Parser (Unparsed Character Data ). "<" And "&" are invalid in XML elements. "<" Produces an error because the parser interprets the character as the beginning of the new element. "&" Also produces errors because the parser interprets the character as the beginning of the character entity.

Some text, such as JavaScript code, contains a large number of "<" or "&" characters. To avoid errors, you can define the script code as CDATA.

All content in the CDATA section is ignored by the parser. (See 4.2)

 

V. Reference:

 

Http://www.duote.com/tech/5/14543.html

 

Http://blog.csdn.net/rwm5366745/article/details/5848949

 

Http://www.yzzmf.com/bbs/forum.php? Mod = viewthread & tid = 1398.

 

Reprinted, please describe the source

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.