C# 在web应用程序之间传递数据

C# 在web应用程序之间传递数据,c#,asp.net,web-applications,C#,Asp.net,Web Applications,我有两个不同的Web应用程序,我想知道如何将数据从第一个Web应用程序发送到第二个Web应用程序,比如在第一个Web应用程序的文本框上写下我的名字,然后在第二个Web应用程序的标签上显示。我见过一些代码,包括responde.redirect、会话变量、cookies、应用程序状态和server.transfer,但总是将数据发送到同一项目中的其他页面。我能用这个吗?我将ASP.Net与C#一起使用 好的,我做到了。它对我有用 web应用程序1 protected void buttonPass

我有两个不同的Web应用程序,我想知道如何将数据从第一个Web应用程序发送到第二个Web应用程序,比如在第一个Web应用程序的文本框上写下我的名字,然后在第二个Web应用程序的标签上显示。我见过一些代码,包括responde.redirect、会话变量、cookies、应用程序状态和server.transfer,但总是将数据发送到同一项目中的其他页面。我能用这个吗?我将ASP.Net与C#一起使用

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

web应用程序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应用程序2

 public void Page_Load(object sender, EventArgs e)
    {

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

使用
Get
方法在querystring中发送数据,然后在接收页面上从中提取值

如果需要保护数据,请使用
POST
方法。使用
WebClient
向url生成请求。在接收页面上,从
POST
变量中提取数据并显示在
标签上

发布方法示例:(请求)

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


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

关于
QueryString
您是否有权更改您希望从第一个网站获取数据的第二个网站的代码?您可以从第一个网站获取值,例如,在链接按钮上单击,然后通过生成这些值的查询字符串将它们传递到其他网站。在接收端,您可以编写代码从query stringok获取值,但如何获取我在第二个web应用程序的第一个web应用程序中写入的值?请查看是否正确@AdilOk..我正在努力做到这一点,我是一个网络应用程序的新手,我已经添加了使用POST方法发送和接收数据的示例代码。试试看,很简单。
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);
}
NameValueCollection postData = Request.Form;
string name, username;
if (!string.IsNullOrEmpty(postData["name"]))
{
  name = postData["name"];
}
if (!string.IsNullOrEmpty(postData["username"]))
{
  username = postData["username"];
}