Problems encountered during URL rewriting and my Solutions

Source: Internet
Author: User

URL rewriting environment.
When using the control, I found that a script error occurred while moving the mouse over. debugging. I found it all at once ..
Webresource. axd was originally rewritten. The result location is incorrect. js cannot be loaded in.

After the solution is completed, it is found that when you move the mouse over the menu, it is found.

Xxx.dddd.com/test.aspx

The menu path has changed. It was originally default. aspx and now it has changed to a.dddd.com/xxx/default.aspx with another xxx
It is the path that I rewrite Based on domain name conditions.

The solution is to change the original default. aspx ~ /Default. aspx can be accessed through URL rewriting paths,

Http://www.dddd.com/xxx/test.aspx access to the path is not right into the http://www.dddd.com/default.aspx into this. It should have been a http://www.ddd.com/xxx/default.aspx

The reason is that the control itself processes the jump address. If you can cancel the processing, you can OK. (to be continued)
Fortunately, you don't have to access it with a http://www.ddd.com/xxx/test.aspx.

The following code solves the form submission problem (copied online)

Public class templatebasepage: Page
{
Public templatebasepage ()
{

}
/**//**/
/** // <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 );
}



}
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 );
}
}
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 );
}
}

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.