Can data be transmitted between two different sites? I want to transfer the data of Site A to Site B .......
Cache is recommended.
(1) it is unlikely that the program performance will not be affected. As you have said, it is a large amount of data. For example, you are uploading data from A. aspx to B. aspx. If two users access A, will your data not affect different clients? If this is the case, you will not be able to use the Cache (not absolutely unavailable, but you must differentiate the client and do more work). You can only use Session and Cookies, viewState, QueryString, Form, and other methods.
The second condition: if more than one page needs this operation, such as. aspx and B. aspx must transmit "a large amount of data" to C. aspx, so if you have a Session, you cannot make it overwrite each other. Therefore, if there is a small amount of data, such as only a number, ViewState, QueryString, and Form can all be used, but they need to make another round trip to the server and client. If you have a large amount of data, QueryString cannot be used. ViewState is actually Form. You can consider the actual situation and select a specific method.
(2) Use the Server. Transfer Method
This can be said to be the method used for face object development. It uses Server. the Transfer method directs the process from the current page to another page. The new page uses the response stream of the previous page. Therefore, this method is completely object-like and concise and effective. The following code shows the method used when many parameters are required. If there are few parameters, it is unnecessary to use this method.
If you want all query pages to inherit an interface and define a method in this interface, the only function of this method is to obtain the parameters required for building the result on the result page, you can share multiple pages with one result page!
1. Define a class and use it to place all query parameters.:
Copy codeThe Code is as follows:
/** // <Summary>
/// Summary of QueryParams
/// </Summary>
Public class QueryParams
{
Private string firstName;
Private string lastname;
Private int age;
Public string Firstname
{
Get {return this. firstname ;}
Set {this. firstname = value ;}
}
Public string LastName
{
Get {return this. lastname ;}
Set {this. lastname = value ;}
}
Public string Age
{
Get {return this. age ;}
Set {this. age = value ;}
}
}
2. Interface Definition:
Copy codeThe Code is as follows:
/** // <Summary>
/// Define the query interface.
/// </Summary>
Public interface IQueryParams
{
/** // <Summary>
/// Parameters
/// </Summary>
QueryParams Parameters {get ;}
}
3. the query page inherits the IQueryParams interface (QueryPage. aspx):
QueryPage. aspx
Copy codeThe Code is as follows:
<Form id = "form1" runat = "server">
<Div>
<Asp: TextBox ID = "txtFirstName" runat = "server"> </asp: TextBox>
<Asp: TextBox ID = "txtLastName" runat = "server"> </asp: TextBox>
<Asp: TextBox ID = "txtAge" runat = "server"> </asp: TextBox>
<Asp: Button ID = "btnEnter" runat = "server" Text = "Button" OnClick = "btnEnter_Click"/> </div>
</Form>
QueryPage. aspx. cs
Copy codeThe Code is as follows:
Public partial class QueryPage: System. Web. UI. Page, IQueryParams
{
Private QueryParams queryParams;
Public QueryParams Parameters
{
Get
{
Return queryParams;
}
}
Public void btnEnter_Click (object sender, System. EventArgs e)
{
// Assign a value
QueryParams = new QueryParams ();
QueryParams. FirstnName = this.txt FirstName. Text;
QueryParams. Lastname = this.txt LastName. Text;
QueryParams. Age = this.txt Age. Text;
Server. Transfer ("ResultPage. aspx ");
}
Protected void Page_Load (object sender, EventArgs e)
{}
}
4. Receiving page (ResultPage. aspx):
ResultPage. aspx. cs
Copy codeThe Code is as follows:
Public partial class ResultPage: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
QueryParams queryParams = new QueryParams ();
IQueryParams queryInterface;
// Page for implementing this interface
If (Context. Handler is IQueryParams)
{
QueryInterface = (IQueryParams) Context. Handler;
QueryParams = queryInterface. Parameters;
}
Response. Write ("FirstName :");
Response. Write (queryParams. FirstName );
Response. Write ("<br/> Lastname :");
Response. Write (queryParams. LastName );
Response. Write ("<br/> Age :");
Response. Write (queryParams. Age );
}
}