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:
01
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Redirect.aspx.cs" Inherits="Redirect" %>
02
03
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
04
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
05
<
head
runat
=
"server"
>
06
<
title
> Use a browser to redirect users to another page. Response. Redirect () </
title
>
07
</
head
>
08
<
body
>
09
<
form
id
=
"form1"
runat
=
"server"
>
10
<
div
>
11
Select your language:
12
<
br
/>
13
<
asp:DropDownList
ID
=
"LanguagesList"
runat
=
"server"
>
14
<
asp:ListItem
Selected
=
"True"
>China</
asp:ListItem
>
15
<
asp:ListItem
>Deutsch</
asp:ListItem
>
16
<
asp:ListItem
>English</
asp:ListItem<