Yesterday I wrote a URL rewrite, because there is a small bug in the rewritten URL, that is, the address in the original URL will be changed to get in the post data.
For example, the original URL is http: // localhost/test/default. aspx.
URL after Rewriting: http: // localhost/test/2004/12/news. aspx
The default. aspx file contains post data (such as post text ). Then the URL after rewriting will change to: http: // localhost/test/2004/12/news. aspx? Id = 12
Obviously, this is neither the URL we want nor the standard.
Actually, I have read this in msdn on MS.ArticleAll of you know that the problem has been resolved.
Http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx
The link above may be relatively long. Some friends have read the URL rewriting before reading it. The following sections describe how to clear the form action. Here, I insert the following statement: In the webform OF THE Asp.net page, only one form can be displayed on one page, the action of this form is unchangeable (that is, only data can be post back to this page ). If you need to change, you need to write a Form Control, which inherits the system. Web. UI. htmlcontrols. htmlform interface.
Here is the source code download of urlrewriter:
Http://upserver2.ys168.com/ys168up/D1/ys1.aspx? F = msdnurlrewriting. Mismatch
In this source code, find the urlrewriter. dll and actionlessform. dll DLL files. In fact, the entire source code is only useful for these two files.
I don't need to talk about the first one. I already mentioned how to use this DLL. Actionlessform. dll is a control, which is easy to use:
First, import actionlessform. DLL into the bin directory of your project, and then reference this DLL in your vs.net project. In your original (that is, not rewritten). ASPX page
Step 1: add this sentenceCodeTop:
<% @ Register tagprefix = "SKM" namespace = "actionlessform" assembly = "actionlessform" %>
Step 2:
<Form ID = "form1" method = "Post" runat = "server"> and </form>
Replace:
<SKM: Form ID = "form1" method = "Post" runat = "server"> and </SKM: Form>
OK. Now you can run it again.ProgramTry it.
----------
Appendix: Why does the URL change to http: // localhost/test/2004/12/news. aspx? Id = 12
In fact, it is very simple, because there is such a sentence in Web. config:
<Sendto> ~ /Default. aspx? Id = $2 </sendto>
Before you replace the form, you can view the source code of the page. Your form action is (in the above example): default. aspx? Id = 12
That is, the final HTML generated on the. ASPX page is:
<Form ID = "form1" name = "form1" method = "Post" Action = "default. aspx? Id = 12 "> </form>
Also, if you want to rewrite the format with a URL as a directory, you do not need to add default. aspx:
Http://localhost/test/2004/12
Create the corresponding directory and file default. aspx.
Example: http: // localhost/test/2004/12
Create Directory 2004 and directory 12, and then create the default. aspx file under directory 12. File content can be empty.
The reason is that if IIS does not find a directory or file, an error is reported.
Http://community.csdn.net/Expert/TopicView1.asp? Id = 4218777
--------------
Appendix: URL rewriting
Http://www.cnblogs.com/HD/archive/2005/06/20/177633.html
Http://www.cnblogs.com/HD/archive/2005/06/21/178367.html