简体   繁体   中英

Passing data between web applications

I have two different Web applications and I would like to know how to send data from my first web application to second, something like writing my name on a textbox in the first web application and show it on a label in the second web application. I've seen some code with responde.redirect, session variable, cookies, application state and server.transfer but it is always to send data to another pages in the same project. Can I use that anyway? I'm using ASP.Net with C#.

Ok..I did it. It worked for me

web app 1

protected void buttonPassValue_Click(object sender, EventArgs e)
    {

        Response.Redirect("http://localhost:57401/WebForm1.aspx?Name=" +
            this.txtFirstName.Text + "&LastName=" +
            this.txtLastName.Text); }

Web app2

 public void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        this.lblname.Text = Request.QueryString["Name"];
        this.lbllastname.Text = Request.QueryString["Lastname"]; }

Use Get method to send data in querystring then extract values from it on receiving page.

If data needs to be secured, use POST method. Generate a request using WebClient to the url. On receiving page, extract data from POST variables and show on label .

POST method example: (Request)

using (var client = new WebClient())
{
    var values = new NameValueCollection();
    values["name"] = "Name";
    values["username"] = "username";
    var response = client.UploadValues("url of page", values);

    var responseString = Encoding.Default.GetString(response);
}

Read data from POST: (on target page)

NameValueCollection postData = Request.Form;
string name, username;
if (!string.IsNullOrEmpty(postData["name"]))
{
  name = postData["name"];
}
if (!string.IsNullOrEmpty(postData["username"]))
{
  username = postData["username"];
}

您可以尝试创建Web服务以在应用程序之间进行通信。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM