[Code] server-side hidden redirection

Source: Internet
Author: User

Summary
To achieve webpage redirection in ASP. NET, You can implement the following four methods:
1. Redirect through hyperlinks.
2. Use cross-page sending technology to redirect webpages.
3. Redirect web pages through browser programming.
4. Redirect the webpage through the server.

This example shows the fourth redirection method.
That is, callServer. Transfer ()Method. It andResponse. Redirect ()The difference is that the redirection operation is quietly completed on the server.
How do you know?
After the two methods are called, the browser address bar is changed.
After response. Redirect () is called, the browser address is updated to the URL specified by the Redirect () method parameter;
That is to say, redirection is completed by the browser, although the command is issued by the server. However, the browser knows that the webpage has been redirected.
After server. Transfer () is called, the address of the browser is not changed, but the content of the webpage is no longer the content of the Source Page.
That is to say, the server is redirected, but the browser does not know.

ExampleCode
In this demo code, click the redirection button on the Source Page, and the server calls server. Transfer () to redirect the webpage to the page named another. aspx.
The Demo code uses the transfer () overload method that contains the Boolean parameter.
This Boolean parameter indicates whether to retain the data of the query string and form on the page. If the data is retained, the value is true. If the data is not retained, the value is false.
You can also use another method of transfer () to reload the relocated Uri.

Protected void transferbutton_click (Object sender, eventargs e) {This. server. Transfer ("another. aspx", true );}

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.