Force the browser to redirect to another page

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 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<

Related Article

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.