Long time not to write blog, in retrospect, the last blog post should have been written long ago. Today write some of the past learning experience ——. NET to implement pseudo-static.
For example: A link like this list.aspx?id=1&pid=5, we do not want to see in the browser address bar ( Note this sentence ) the suffix and parameter transmission, we want him to become list-1-5.html such. The principle is very simple, the first show to the customer click on the part is written list-1-5.html or other static. html links, such as: list/1/5.html or list_1_5.html, etc., in the foreground part of the writing, the browser regardless of the page you handle, All he knows is that you clicked on a. html (as I understand it), then the browser address bar of the open page is this. html, and then we see that the following part is actually the result of a handler run. It 's called Changing the way the application is handled, letting the processing page run secretly, and pushing it to the front. What I don't understand is: Why does IIS do this: I click on the. html page, but this page does not exist in the directory, usually we request an HTML page, without this file will not be found, right? But here's a bit different, he lets the browser's address part and the handler, which is the ASPX page that receives the parameter, come together, and the address shows what is clicked. html, and then the following section is whether the ASPX process renders or an ASPX page. can understand, but it is a little to understand, not good understanding.
There are 2 ways to talk about pseudo-static. The first type: Use a class to decompose the requested. HTML parameter, plus the simple configuration in Web. config is ok, pass these parameters to the ASPX processing page to process, and then render the result. Another is to configure directly in Web. config, a little more complex, and then he does not have to write a special processing class to let the processing page to the value of the rendering results.
Prerequisites: All without a third-party. dll file: URLRewriter.dll
Make a process, it looks very intuitive:
Create a new Web site in vs2010 (this is my environment)
Refer to the above. dll in the bin file
Create a new ASPX page in the directory to present to the user, where the link is placed, directly:
This is presented to the user to point, always have an entrance bar ~.
First of all, the first way to deal with the above, we said the first is to have a class to decompose this parameter to the processing page that is the. aspx page to process, on the class diagram:
Note here that this class must be placed in the App_Code folder, which captures the value of the request page that the client sends to the server before processing the page, and the value is processed to get the parameter. App_Code This folder is a global folder for a solution, and any request must be preceded by a corresponding method class, such as: Filter the input class can be placed inside, and then capture the request can also be put in it and so on. Anyway, it's in the middle of the process before the process can put this inside (for the moment understand).
The next is the detail.aspx, the file is really processed page,:
OK, finally configure the config file:
Run, set a breakpoint in that class, and he must have gone there.
Here is the second, the only difference is in the Web. config file, the above class is also not, directly on the configuration file diagram:
Well, the rest of the constant, run, is the same result. Second, I feel that the. dll class has also done the processing, how to deal with it? I think that is the config in the configuration is the 2 part of the processing, so simple I think.
Write a personal feeling, combined the first to be simple, why, I understand that a class can handle a lot of different situations, and you configure in config is not so flexible, look at the above Figure 2 of the section, to write like this, If such a large number of processing pages, such as Sina, the config is not quite amazing (although the most can be covered by the most also very inconvenient Ah!). , the processing class is different, the processing page can be placed as a variable in the program, who will change who.
In fact, this is a bit of my personal learning experience, there are different opinions can be pointed to each other. Speaking of which, I am a bit more admire Webconfig this file, Microsoft used this file in the application actually play such a big role, really feel like a frog in the well. Study in ~ ~ ~
Learning summary of pseudo-static implementation in. Net