Struct instead of list. aspx? Page = 1
We need to use the app_browsers directory to store the browser definition file. For more information, see msdn: http://msdn2.microsoft.com/zh-cn/library/ms228122 (vs.80). aspx
<! -- In <WINDIR> \ Microsoft. net \ framework \ <ver> \ config \ browsers find the existing browser definition --> <browsers> <browser refID = "default"> <controladapters> <adapter controltype = "system. web. UI. htmlcontrols. htmlform "adaptertype =" formrewritercontroladapter "/> </controladapters> </Browser> </browsers>
Code As follows:
Public class formrewritercontroladapter: system. web. UI. adapters. controladapter {protected override void render (htmltextwriter writer) {If (httpcontext. current. request. rawurl. contains (". html ") {base. render (New rewriteformhtmltextwriter (writer);} else {base. render (writer) ;}} public class rewriteformhtmltextwriter: htmltextwriter {public rewriteformhtmltextwriter (html32textwriter writer): Base (writer) {This. innerwriter = writer. innerwriter;} public rewriteformhtmltextwriter (system. io. textwriter writer): Base (writer) {This. innerwriter = writer;} public override void writeattribute (string name, string value, bool fencode) {If (name = "action") {If (httpcontext. current. items ["actionalreadywritten"] = NULL) {value = httpcontext. current. request. rawurl; httpcontext. current. items ["actionalreadywritten"] = true ;}} base. writeattribute (name, value, fencode );}}
The above code has been running for a long time, but later I used Asp.net ajax to find that an error occurs on the page after URL rewriting. I modified the code again to exclude Asp.net Ajax requests for processing. The Code is as follows:
Public class formrewritercontroladapter: system. web. UI. adapters. controladapter {protected override void render (htmltextwriter writer) {If (httpcontext. current. request. rawurl. contains (". html ") {// get the Asp.net Ajax request flag var asyncpost = httpcontext. current. request. form ["_ asyncpost"]; If (asyncpost = "true") // determine whether the Asp.net Ajax request {base. render (writer);} else {base. render (New rewriteformhtmltextwriter (writer) ;}} else {base. render (writer) ;}} public class rewriteformhtmltextwriter: htmltextwriter {public rewriteformhtmltextwriter (html32textwriter writer): Base (writer) {This. innerwriter = writer. innerwriter;} public rewriteformhtmltextwriter (system. io. textwriter writer): Base (writer) {This. innerwriter = writer;} public override void writeattribute (string name, string value, bool fencode) {If (name = "action") {If (httpcontext. current. items ["actionalreadywritten"] = NULL) {value = httpcontext. current. request. rawurl; httpcontext. current. items ["actionalreadywritten"] = true ;}} base. writeattribute (name, value, fencode );}}
After debugging, it was found that there was a problem with the rewriteformhtmltextwriter constructor, which did not contain the htmltextwriter constructor. However, the textwriter constructor was used, resulting in a page structure error and a null error. The code is adjusted as follows:
Public class formrewritercontroladapter: system. web. UI. adapters. controladapter {protected override void render (htmltextwriter writer) {If (httpcontext. current. request. rawurl. contains (". html ") {// use the method used to filter out Asp.net Ajax requests to avoid errors // and then find the rewriteformhtmltextwriter constructor problem, then discard the method // var asyncpost = httpcontext. current. request. form ["_ asyncpost"]; // If (asyncpost = "true") // {// base. render (writer); // else // {// base. render (New rewriteformhtmltextwriter (writer); //} base. render (New rewriteformhtmltextwriter (writer);} else {base. render (writer) ;}} public class rewriteformhtmltextwriter: htmltextwriter {// public rewriteformhtmltextwriter (htmltextwriter writer): Base (writer) {This. innerwriter = writer. innerwriter;} // uses the HTML 3.2 Renderer and is compatible with the public rewriteformhtmltextwriter (html32textwriter writer): Base (writer) {This. innerwriter = writer. innerwriter;} // other browsers may cause the null error public rewriteformhtmltextwriter (system. io. textwriter writer): Base (writer) {This. innerwriter = writer;} public override void writeattribute (string name, string value, bool fencode) {If (name = "action") {If (httpcontext. current. items ["actionalreadywritten"] = NULL) {value = httpcontext. current. request. rawurl; httpcontext. current. items ["actionalreadywritten"] = true ;}} base. writeattribute (name, value, fencode );}}
about htmltextwriter and html32textwriter, you can take a look at this Article http://www.cnblogs.com/Vegaslee/archive/2007/12/04/982723.html