asp.net url rewrite after page return problem _ Practical skills

Source: Internet
Author: User
The specific approach is as follows: You can override the default HtmlTextWriter method by customizing the page base class, overriding the property output WriteAttribute (string name, string value, bool encode) method, when the output action is Casts the value of the Action property to the current virtual URL (HttpContext.Current.Request.RawUrl, ~/showvisasall_ (\w+) \.aspx)
The last thing is to have all the pages call the base class and modify the web.config.
<!--Openlab.Controls.OLPage is the base class for the page, Openlab.controls is the DLL that contains the base class-->
<pages pagebasetype= "Openlab.Controls.OLPage, Openlab.controls"/>
Complete code with page base class (reference CS code complete):
Copy Code code as follows:

Using System;
Using System.IO;
Using System.Web;
Using System.Web.UI;
Namespace Openlab.controls
... {
/**////<summary>
Page base class
</summary>
public class Olpage:page
... {
Public Olpage ()
... {
}
Render#region Render
/**////<summary>
Overrides the default HtmlTextWriter method, modifying the Value property in the form tag so that its value is the overridden URL instead of the real URL.
</summary>
<param name= "Writer" ></param>
protected override void Render (HtmlTextWriter writer)
... {
If (writer is System.Web.UI.Html32TextWriter)
... {
writer = new Formfixerhtml32textwriter (writer. Innerwriter);
}
Else
... {
writer = new Formfixerhtmltextwriter (writer. Innerwriter);
}
Base. Render (writer);
}
#endregion
}
Formfixers#region formfixers
Formfixerhtml32textwriter#region Formfixerhtml32textwriter
Internal class FormFixerHtml32TextWriter:System.Web.UI.Html32TextWriter
... {
private string _url; Fake URL
Internal Formfixerhtml32textwriter (TextWriter writer): Base (writer)
... {
_url = HTTPCONTEXT.CURRENT.REQUEST.RAWURL;
}
public override void WriteAttribute (string name, string value, bool encode)
... {
If the current output property is a form-marked Action property, the value is replaced with the overridden false URL
if (_url!= null && string.compare (name, action, true) = = 0)
... {
value = _url;
}
Base. WriteAttribute (name, value, encode);
}
}
#endregion
Formfixerhtmltextwriter#region Formfixerhtmltextwriter
Internal class FormFixerHtmlTextWriter:System.Web.UI.HtmlTextWriter
... {
private string _url;
Internal Formfixerhtmltextwriter (TextWriter writer): Base (writer)
... {
_url = HTTPCONTEXT.CURRENT.REQUEST.RAWURL;
}
public override void WriteAttribute (string name, string value, bool encode)
... {
if (_url!= null && string.compare (name, action, true) = = 0)
... {
value = _url;
}
Base. WriteAttribute (name, value, encode);
}
}
#endregion
#endregion
}

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.