。 NET page Jump Daquan

Source: Internet
Author: User
Tags security essentials

①response.redirect
This jump page method jumps fast because it wants to go 2 back and forth (2 times postback), but he can jump to any page, no site page limit (ie can be jumped from Yahoo to Sina), and cannot skip login protection. But slow is its biggest flaw!redirect jump mechanism: The first is to send an HTTP request to the client, the notification needs to jump to a new page, and then the client sends a jump request to the server side. It is important to note that all data stored in the internal space after the jump is lost, so the session needs to be used.
Instance
Example that uses Redirect [C #; ASP]

Copy CodeThe code is as follows:
Using System;
Using System.Web.UI;
Namespace WebApplication1
{
public partial class List:page
{
protected void Page_Load (object sender, EventArgs e)
{
Get Response.
var response = base. Response;
Redirect temporarily.
// ... Don ' t throw a httpexception to terminate.
Response. Redirect ("Http://www.jb51.net", false);
}
}
}


Result of the page

Copy CodeThe code is as follows:
http/1.1 302 Found
content-type:text/html; Charset=utf-8
Location:http://www.jb51.net
server:microsoft-iis/7.0
Date:fri, 21:18:34 GMT
content-length:144
</body>


②sever.execute
This method is mainly used on the page design, and he must jump to the same site under the page. This method is used when inserting the output of one page into another ASPX page, most of which is in a table, where a page is similar to a nested way in another page.
Let's take a look at:
1. Create a Web Form
2. Place a button1 in the new Web form, placing two Textbox1,textbox2
3. Create Click events for button buttons
The code is as follows:

Copy CodeThe code is as follows:
private void button1_click
(object sender, System.EventArgs e)
{
Server.Transfer ("webform2.aspx");
}


4. Create the procedure to return the value code for the Textbox1,textbox2 control as follows:

Copy CodeThe code is as follows:
public string Name
{
Get
{
return TextBox1.Text;
}
}
public string EMail
{
Get
{
return TextBox2.Text;
}
}


5. Create a new target page named WebForm2
6. Place two Label1,label2 in WebForm2
Add the following code to the WebForm2 Page_Load:

Copy CodeThe code is as follows:
private void Page_Load
(object sender, System.EventArgs e)
{
Create an instance of the original form
WebForm1 WF1;
Get the instantiated handle
wf1= (WebForm1) Context.Handler;
Label1.text=wf1. Name;
Label2.text=wf1. EMail;
}


③server.transfer
Fast, only need one postback, but .... He must be under the same site because it is a method of server. In addition, he can skip login protection. You can write a small program to try: Design a jump from page to page two, but to enter the page two need to login, form authentication, but if the jump statement using transfer, then it will not pop up the login page. The redirect request for this method occurs on the server side, so the URL of the browser is still reserved for the original page's address!

Copy CodeThe code is as follows:
<%@ page language= "C #" autoeventwireup= "true" codefile= "WebForm1.aspx.cs" inherits= "WebForm1"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:textbox id= "TextBox1" runat= "Server" ></asp:textbox><br/>
<asp:button id= "Button1" runat= "Server" text= "button" onclick= "Button1_Click"/>
</div>
</form>
</body>
. NET code
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
public partial class WebForm1:System.Web.UI.Page
{
public string Time
{
get {return DateTime.Now.ToString ();}
}
public string Testfun ()
{
Return "Function of WebForm1 called";
}
protected void Page_Load (object sender, EventArgs e)
{
CONTEXT.ITEMS.ADD ("Context", "context from Form1");
}
protected void Button1_Click (object sender, EventArgs e)
{
This. TextBox2.Text =request ["TextBox1"]. ToString ();
Server.Transfer ("Webform2.aspx", true);//When the second argument is false, the contents of TextBox1 are not available in webform2.aspx
}
}


Summary:
If you want to capture the output of an ASPX page and then insert the result into a specific location on another ASPX page, use Server.Execute.
• If you want to ensure that the Html output is legitimate, use Response.Redirect because the page that Server.Execute or Server.Transfer method returns to the client contains multiple <Html><body> tags , not a legitimate HTML page, and errors may occur in non-IE browsers.

1.response.redirect ("Http://www.jb51.net", false);
The target page and the original page can be on 2 servers, and you can enter a URL or relative path. The bool value that follows is whether to stop executing the current page.
Jump to a new page, the original window is replaced. "
The URL in the browser is the new path.
: The Response.Redirect method causes the browser to link to a specified URL. When the Response.Redirect () method is called, it creates an answer that is indicated in the answer header
Status Code 302 (indicates that the target has changed) and the new destination URL. The browser receives the reply from the server and uses the information in the reply header to make a request to the new URL. Say
When using the Response.Redirect method, the redirect operation occurs on the client, involving a total of two communications with the server (two back and forth): the first is a request to the original page,
Get a 302 answer, and the second is a new page declared in the Request 302 reply, to get the page after the redirect.
2.server.transfer ("Default2.aspx?name=zhangsan", true);
The target page and the original page can be on the same server.
Jump to a new page, the original window is replaced.
Wave Ball Forum The URL in the browser is the same as the original path.
By default, the Server.Transfer method does not pass the form data or query string from one page to another, but only if the second parameter of the method is set to
Tb310true, you can keep the form data and query strings for the first page.
At the same time, it should be noted when using Server.Transfer: The target page will use the original page to create the answer stream, which results in the machine validation check of ASP. b310, Bo Ball, Bo Net, insider heart water, race recommendation, race analysis, database, football tournament, basketball, NBA, odds, Score, basketball data, football data.

(machine authentication Check,mac) that the viewstate of the new page has been tampered with. Therefore, if you want to preserve the form data and query string collections of the original page,
You must set the enableViewStateMac property of the page directive of the target pages to false.
3.server.execute ("default5.aspx?address=beijing");
The target page and the original page can be on the same server.
Jump to a new page, then jump to the original page.
The URL in the browser is the same as the original path.
When the specified ASPX page finishes executing, the control flow returns to the original page where the Server.Execute call was made.
This kind of page navigation is similar to a function call on an ASPX page, where the called page has access to the form data and query string collection that made the calling page, so
The enableViewStateMac property of the paged page directive is set to false.
4.response.write ("<script language= ' JavaScript ' >window.open (' aaa.aspx ');</script>"); _
The target page and the original page can be on 2 servers, and you can enter a URL or relative path.
The original window is reserved and another new page is added.
5.response.write ("<script language= ' javascript ' >window.location= ' default2.aspx ' </script>");
Open a new page, the original window is replaced.
6.response.write ("<script>window.showmodaldialog (' default2.aspx ') </script>");
7.response.write ("<script>window.showmodelessdialog (' default2.aspx ') </script>");
(a), what is the difference between ShowModalDialog and showModelessDialog?
ShowModalDialog: The input focus is always maintained when it is opened. The user cannot switch to the main window unless the dialog box is closed. The effect is similar to alert operation. B310,, Bo Ball, Bo Net, insider heart water, race recommendation, race analysis, database, soccer tournament, basketball, NBA, odds, score, basketball data, football data
showModelessDialog: After being opened, the user can randomly switch the input focus. Has no effect on the main window (at most, it is blocked.) :P)
(b), how to let the ShowModalDialog and showModelessDialog hyperlinks do not pop up a new window?
Add <base target= "_self" > on the page that is opened. This sentence is usually placed between

Microsoft Security Essentials

。 NET page Jump Daquan

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.