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