The specific method is as follows: You can use the custom page base class to override the default htmltextwriter method, and rewrite the attribute output writeattribute (string name, string value, bool encode) method. when the action is output, forcibly convert the value of the action attribute to the current virtual URL (httpcontext. current. request. rawurl, above ~ /Showvisasall _ (\ W +) \. aspx)
Finally, let all the pages call this base class and modify web. config.
<! -- Openlab. Controls. olpage is the page base class, And openlab. Controls is the base class DLL -->
<Pages pagebasetype = "openlab. Controls. olpage, openlab. Controls"/>
Complete Page Base Class Code (Refer to the CS code to complete ):
Copy code The Code is 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>
/// 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.
/// </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; // a false 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 attribute is the form-marked action attribute, replace the value with the rewritten 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
}
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.