Problems caused by URL rewriting to Asp.net Ajax

Source: Internet
Author: User

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

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.