Retain the PostBack address after URL rewriting

Source: Internet
Author: User

Integrate all pages with the following classes to rewrite the URL and retain the PostBack address.

 Using system;
Using system. Web;
Using system. Web. UI;
Using system. IO;
Using system. text;
Using system. Text. regularexpressions;
Using system. configuration;

Namespace BLL
{
/// <Summary>
/// Summary of pagebase.
/// </Summary>
Public class pagebase: Page
{
Private Static object OBJ = new object ();
//// <Summary>
/// Rewrite the default htmltextwriter method, modify the value attribute in the form tag, and set the value to the rewritten URL instead of the real URL.Www.svnhost.cn
/// </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 );
}
}

Public class formfixerhtml32textwriter: system. Web. UI. html32textwriter
{
Public formfixerhtml32textwriter (textwriter writer)
: Base (writer)
{
}

Public override void writeattribute (string name, string value, bool encode)
{
// If the current output attribute is the form-marked action attribute, replace the value with the rewritten false URL
If (string. Compare (name, "action", true) = 0)
{
Value = httpcontext. Current. Request. rawurl;
}
Base. writeattribute (name, value, encode );
}
}


Public class formfixerhtmltextwriter: system. Web. UI. htmltextwriter
{
Public formfixerhtmltextwriter (textwriter writer)
: Base (writer)
{
}

Public override void writeattribute (string name, string value, bool encode)
{
If (string. Compare (name, "action", true) = 0)
{
Value = httpcontext. Current. Request. rawurl;
}

Base. writeattribute (name, value, encode );
}
}
}
Reprinted: http://www.svnhost.cn/Article/Detail-123.shtml

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.