在Web应用程序之间传递数据

时间:2015-05-07 10:40:05

标签: c# asp.net web-applications

我有两个不同的Web应用程序,我想知道如何将数据从我的第一个Web应用程序发送到第二个,比如在第一个Web应用程序的文本框中写下我的名字,并在第二个Web上的标签上显示应用。我已经看到了一些带有responde.redirect,会话变量,cookie,应用程序状态和server.transfer的代码,但总是将数据发送到同一项目中的另一个页面。我还能用吗?我正在使用ASP.Net和C#。

好的..我做到了。它对我有用

网络应用1

protected void buttonPassValue_Click(object sender, EventArgs e)
    {

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

网络应用2

 public void Page_Load(object sender, EventArgs e)
    {

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

2 个答案:

答案 0 :(得分:4)

使用POST方法在查询字符串中发送数据,然后在接收页面上从中提取值。

如果需要保护数据,请使用WebClient方法。使用POST向网址生成请求。在接收页面时,从label变量中提取数据并显示在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); }

POST方法示例:(请求)

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

从POST中读取数据:(在目标页面上)

$(document).ready(function(){
  // Our data renderer function, returns an array of the form:
  // [[[x1, sin(x1)], [x2, sin(x2)], ...]]
  var sineRenderer = function() {
    var data = [[]];
    for (var i=0; i<13; i+=0.5) {
      data[0].push([i, Math.sin(i)]);
    }
    return data;
  };

  // we have an empty data array here, but use the "dataRenderer"
  // option to tell the plot to get data from our renderer.
  var plot1 = $.jqplot('chart1',[],{
      title: 'Sine Data Renderer',
      dataRenderer: sineRenderer
  });
});

答案 1 :(得分:-1)

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

相关问题