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 how to redirect through a browser.
In fact, using a browser for redirection is also divided into two situations:
One case is to write the client script for redirection. This example does not include this demonstration.
In addition, the server forces the browser to redirect, that is, call the response. Redirect () method. This is the focus of this sample code demonstration.
Before calling the Redirect () method, set response. bufferoutput to true, that is, to enable content buffering.
Sample Code
A drop-down list is provided on the webpage, which lists some languages that users may use. You can select any language in the list and click Change Language to send the webpage back to the server.
Then, the server redirects to the appropriate webpage based on the language selected by the user. For more information, see the code:
Webpage Interface Design:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "Redirect. aspx. cs" inherits = "Redirect" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
The code for redirection is as follows, that is, the event handler code for clicking the Change Language button:
protected void ChangeLanguageButton_Click(object sender, EventArgs e){ this.Response.BufferOutput = false; switch (this.LanguagesList.SelectedValue) { case "China": this.Response.Redirect("China.htm"); break; case "Espa?ol": this.Response.Redirect("Espa?ol.htm"); break; case "Deutsch": this.Response.Redirect("Deutsch.htm"); break; default: this.Response.Redirect("English.htm"); break; }}