Principles and efficiency of ASP. NET 2.0 "cross-network Internet sharing"

Source: Internet
Author: User
Tags website hosting

To redirect a user to another region, except for hyperlink, response redirect, and server transfer of the protocol, Asp. NET 2.0 also added a unique "cross-page posting" mechanism.

In "Cross-Site public access", http post is used to call the target page. In addition to the way in which the website URL querystring contains the number, you can also set the ID and content of all the controls on the Source Page (including the user's internal value ), each cursor is automatically taken to the target page. To use this mechanism, you must go through the buttons, imagebutton, and linkbutton controls on the Source Page.Postbackurl adequacy, PostBack the Response Surface to other webform web pages (in Javascript, the new webform_dopostbackwithoptions function replaces the previous _ dopostback function), instead of PostBack to its own response surface.

The URL querystring of the website hosting system contains a large number of values to be redirected to the target page,ProgramEmployees must manually register a large number of data names and their values. This not only lacks the flexibility, but also requires a lot of code to be written during the time. The "Cross-Site public access" is causedYou can directly catch the control in the previous source page in the target page.Therefore, we can reduce the number of generations.

Next, let's look at a typical example. As shown in figure 1, there is a gridview control in the first partition (soruce page), and two textbox allow the user to perform fuzzy search for the keyword. The second partition (target page) there is a formview control, and the hiddenfield control that cannot be seen on the two sides. The hiddenfield is used to store the data in the first region, but it passes through the "cross-Network Public Sector, the two query keywords that the user calls.


When 1 passes through the cross-page posting value between the two sides

Public   Partial   Class Pagedomaingridview: system. Web. UI. Page
{
Protected   Void Gridview1_rowdatabound ( Object Sender, gridviewroweventargs E)
{
For ( Int I =   0 ; I < Gridview1.rows. Count; I ++ )
{
// Through the postbackurl adequacy of the button, the website is PostBack to another website.
(Button) gridview1.rows [I]. findcontrol ( " Btnro " ). Postbackurl =   " Page2_formview.aspx? Type = 1 " ;
(Button) gridview1.rows [I]. findcontrol ( " Btnedit " ). Postbackurl =   " Page2_formview.aspx? Type = 3 " ;
(Button) gridview1.rows [I]. findcontrol ( " Btndelete " ). Postbackurl =   " Page2_formview.aspx? Type = 4 " ;

The relation between values sent by the first vertex (Source Page) of Generation 1

Public   Partial   Class Page2_formview: system. Web. UI. Page
{
Protected   Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback) // If the primary plane is the first primary line
{
// Obtain the first dataset. The search keyword entered by the user in the two textbox is hidden in the two hiddenfields of the current dataset (the second dataset, so that when the first response is returned, The SQL WHERE clause that can be used to return to the two textbox In the first region.
If (Previouspage ! =   Null )
{
// Determine the container Based on iscrosspagepostback encoding and obtain the ID and content of the control in the first batch.
If (Previouspage. iscrosspagepostback)
{
// Tbcomp_num and tbcomp_name are the IDs of the two textbox of the previous vertex (the first vertex ).
Hfkeyword1.value = (Textbox) previouspage. findcontrol ( " Tbcomp_num " ). Text;
Hfkeyword2.value = (Textbox) previouspage. findcontrol ( " Tbcomp_name " ). Text;
}
}
}
}   // End of page_load ()

Generation 2 Second Percentile (target page)

If the source page and target page are in the same web application, the target page can still access the public properties of the class in the Source Page ). The following describes how to use directive for access:
<% @ Previouspagetype virtualpath = "~ /Page1_gridview.aspx "%>
Or
<% @ Reference virtualpath = "~ /Page1_gridview.aspx "%>

In addition, "cross-site Public Access" can also be used to navigate between multiple "user control ).

"Cross-Site public access" is actually achieved through viewstate transition. When "Cross-Site public access" is used in the source page, a new hidden location called "_ previouspage" is created. This bitwise stores the information about the posting page, allowing the target page to use stateful reference for the "Caller interface" object. Example:

<Input type = "hidden" name = "_ previouspage" id = "_ previouspage"
Value = "p1-dFHlCpgH2alr1vkr3G21UIR7jOuzn074led6lbGf1KQ47_F25GwG0"/>

This parameter applies to the previouspage of pages added by. NET 2.0.

The target page of "Cross-Site public access" removes the viewstate of the Source Page and saves it as another copy. After the target page is merged, save the saved viewstate to a new previouspage instance which is the same as the source page. Therefore, the target page can access the control content or public properties of the Source Page. However, since "cross-site internet access" involves a series of activities such as "Saving viewstate, implementing, and returning viewstate to previouspage instance, in contrast, WAF also consumes the system resources of web servers. If viewstate has a large volume of content, the cost of memory storage and original storage will also increase. Therefore, when using the "Cross-Site public access" and the official URL querystring parameter number, it must be handled by the program staff, instead of using the latest technology when developing new cases or components.

-------------------------------------------------
(In this article, the release date of is 2006/08/02)

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.