Multiple methods for page jump in asp.net

Source: Internet
Author: User
Tags comparison html page http request

Asp tutorials. net page jump methods

//// Encrypted // byte [] bb = Encoding. UTF8.GetBytes ("aaa"); // string cc = Convert. ToBase64String (bb );
//// Decrypt // byte [] bb1 = Convert. FromBase64String (cc); // string PC3 = Encoding. GetEncoding ("gb2312"). GetString (bb1 );

Submit a form with a hyperlink
Add id = "form1", <form id = "form1" action = ''.." to form ''.."
<Script>
Function f () {var form1 = document. getElementById ("form1 ");
Form1.submit ();}
</Script>
<A href = "#" onclick = "f ()"> Submit </a>.
Encryption: hide the address bar of IE and the address bar of IE in the menu bar to hide the URL of the webpage. In this way, even if you see the source file, it is not easy to convert the relative address of the image in the HTML source file to an absolute address. Hide the IE menu bar. This function is used with the disabled right-click button, so that the viewer cannot view the source file, which greatly enhances the confidentiality of the webpage code. Encryption Method: for important webpages, if they are opened with hyperlinks, we do not need common hyperlink code, for example, "<A href =" URL address "> Link prompts </A> ". We use the window in JavaScript. open this function opens the page to be encrypted, and uses window. the open function can customize the pop-up window, such as the appearance, size, and position of the pop-up window to adapt to the specific situation of the page. See the following code example.

<A href = # onClick = "window. open ('main.htm', 'newwindow', 'height = 100, width = 400, top = 0, left = 0, toolbar = no, menubar = no, scrollbars = no, resizable = no, location = n o, status = no') "> Note: The preceding parameter description must be a line: window. open the command to pop up a new window; 'page.html 'the name of the pop-up window; 'newwindow' the name of the pop-up window (not the name of the file), not required, can be replaced by null; height = 100 window height; width = 400 window width; top = the pixel value between the 0 window and the top of the screen; left = the pixel value between the 0 window and the left of the screen; toolbar = no indicates whether to display the toolbar. yes indicates display. menubar and scrollbars indicate dishes. And scroll bar. Resizable = no whether to change the window size, yes is allowed; location = no whether to display the address bar, yes is allowed; status = no whether to display the information in the status bar (usually the file has been opened), yes is allowed;

From this point of view, we can set the parameter location = no; menubar = no to hide the address bar and menu bar. (3) decryption: The method mentioned above still has some shortcomings. Although the address bar and menu bar of IE have been hidden, the viewer cannot see the URL address of the current webpage, however, if the CTRL key is not disabled, the viewer only needs to press CTRL + N to open the same page in a new window, the address bar and menu of the IE window are not hidden! Therefore, if you want to make the encryption method more confidential, you must also invalidate the CTRL key that the viewer presses.
In addition, using Tencent's browser can remove the restriction of hiding the IE address bar and menu bar in the new window. open in the webpage code.

1 Response. the Redirect Method does not jump quickly because it takes two rounds (two postback), but it can jump to any page, there is no website page restriction (that is, you can jump from Yahoo to Sina), and you cannot skip logon protection. However, slow speed is the biggest defect! Redirect jump mechanism: first, 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. It should be noted that after the jump, all data information stored in the internal space will be lost, so session is required.

2 Server. Rransfer is fast, only one postback is required, .... It must be on the same site because it is a server method. In addition, he can skip logon protection. You can try to write a small program: design a jump from page 1 to page 2, but to enter page 2, you need to log on and perform form authentication. However, if the jump statement uses transfer, the logon page will not pop up. The redirection request of this method occurs on the server, so the url address of the browser still retains the address of the original page!

3 Sever. Execute this method is mainly used in the page design, and he must jump to the page under the same site. This method needs to be used to insert the output results of a page to another aspx page. Most of them are in the table, where a page is nested to another page.

Summary:
 

1. Server. Transfer can only jump to the page specified by the local virtual directory, while Response. Redirect is very flexible;
2. Server. Transfer can easily pass the page parameters to the specified page;
3. When Server. Transfer jumps to another page during use, the address displayed by the browser will not change, and sometimes it will lead to misunderstanding. Of course, this effect is also required in some occasions;
4. Server. Transfer can reduce client requests to the Server;

2. response. redirect actually sends a command (including a new address) to the browser when the server encounters this statement, and then asks the browser to send an http request and request response. the new http address next to redirect. The process is as follows:

Browser ASP file request-> server execution-> response. redirect statement-> The server sends response. the address after redirect is sent to the client browser-> the browser requests to execute the new address (the server returns the Response. the address after Redirect) this is a small Response. the entire Redirect process, don't look at it, don't know, just look at it! It has so many processes, which are really scary... while the Server. Transfer statement in ASP3.0 directly redirects to the following address after receiving the address. The process is as follows:

Browser ASP file request-> Server execution-> Server. Transfer statements-> Server redirection to new files.

Server. compared with the Redirect method, the Transfer method has another significant advantage in that the content in the Request set will not be lost during page conversion, this makes programming very convenient (I will not mention the specific example, ^ _ ^ ).

Generally, use the Server. Transfer method as much as possible (the premise is that the Server is IIS). The Server. Transfer method is faster and can be compatible with any browser because it is only executed on the Server.

 

Use redirect to redirect a user to a page on another server.

When you need to redirect a user to a non-aspx page, for example, html uses redirect

When the query string needs to be retained to the server as part of the url, because the other two methods cannot achieve two postback operations, the data is first brought back to the server using redirect

Switch between aspx pages (logon not involved) using transfer

Execute is used to insert the output result of the aspx page to another aspx page.

Of course, I forgot another hyperlink! Of course, you don't need to talk too much about this. He uses hyperlinks when a user needs to decide when to jump to a page.

By the way, how to use the redirect method to use Chinese characters in query strings is often garbled because URLs do not support Chinese characters. In this case, the conversion is required:

String message = server. urlencode ("Welcome to the racing column ");

Convert the query string first.

Response. redirect ("webform2.aspx? Msg = "+ message );

Comparison of Methods for redirecting from one page to another using Asp. Net

There are many ways to achieve page jump, except that the server control is encapsulated by the asp.net tutorial, other methods are available in asp.

In so many implementation methods, the same function is implemented. Why do we need to support so many methods? Our actual application

Which method should be selected? Maybe most of us need to jump and use it whenever we think of it,

I never thought about them differently. In fact, I used to do the same before. I cannot give full play to their understanding of none of them.

Their respective advantages. Okay. Now let's take a look at their respective purposes.

I. Superkeys

This is not to mention, the simplest.

II. Server controls

HyperLink

Use the NavigateUrl attribute to specify the url to jump.

It is mainly used by the user to determine when to convert pages, but the program is used to control the conversion target.

III. Program control

1. Response. Redirect ()

Server -------- notify client ---------- request jump to server

It is mainly used to pass the query string as part of the url to another page, or the page to jump to is an html page

2. Server. Transfer ()

The biggest feature of this method is that the url is still the url of the page before the jump.

It is mainly used to transfer the execution process to another aspx page of the same web server. Because it is retained after the jump

Request and session values, and the data on the page before the jump can be used.

3. Server. Execute ()

After this method is executed, the program control will return the next generation code of the jump code, which is equivalent to our modal window.

The return value of the redirected page. It is often used to assist in selection, and then return the selected value to the current page.

With the above introduction, we should choose different jump methods when appropriate.

Comparison of four page jump technologies in asp.net web pages

There are four page navigation methods in asp.net. How do I select one for your page?

· If you want users to decide when to convert a page and which page to go to, hyperlink is the most suitable.

· If you want to use a program to control the conversion target, but the conversion time is determined by the user, use the HyperLink control of the Web server to dynamically set its NavigateUrl attribute.

· If you want to connect a user to resources on another server, use Response. Redirect.

· Use Response. Redirect to connect users to non-ASPX resources, such as HTML pages.

· If you want to retain the query string as part of the URL, use Response. Redirect.

· If you want to transfer the execution process to another ASPX page of the same Web Server, you should use Server. transfer instead of Response. redirect, because Server. transfer can avoid unnecessary network communication to achieve better performance and browsing performance.

· If you want to capture the output result of an ASPX page and insert the result to a specific location of another ASPX page, use Server. Execute.

· To ensure that the HTML output is valid, use Response. Redirect instead of Server. Transfer or Server. Execute.

About Server. Execute,

This page navigation method is similar to calling the callback function for the ASPX page. The called page can access the form data and query string set of the calling page, therefore, set the EnableViewStateMac attribute of the called Page command to False.

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.