Read Response.write in another Page

10,054

Solution 1

It seems you have a value on Sender.aspx that you need to display in receiver.aspx. This is how you can do it.

//On Page_Load of sender.aspx 

Session["fromSender"] = "Hello";
Respone.Redirect("receiver.aspx");
Response.End();

//On Page_Load of receiver.aspx 

if(!string.IsNullOrEmpty(Session["fromSender"].ToString()))
    Response.Write(Session["fromSender"].ToString());

EDIT

In case of change in domain, immediate easy way is to pass the value in query-string.

//On Page_Load of sender.aspx 

Response.Redirect("http://www.receiverdomain.com/receiver.aspx?fromSender=Hello");
Response.End();

//On Page_Load of receiver.aspx 

if(!string.IsNullOrEmpty(Request.QueryString["fromSender"].ToString()))
    Response.Write(Request.QueryString["fromSender"].ToString());

You may observe that the code pattern remains the same and container that is used to transfer the value changes from Session to QueryString.

EDIT2

If security is a concern with you in this case and you don't wish to expose the value ["Hello"], then here comes another way that can help you. In this solution we will first redirect the page to receiver and then from receiver it shall ask for the value to sender. So first we'll write the code for receiver.

//On Page_Load of receiver.aspx 
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        //Remember to use System.Net namespace
        HttpWebRequest requestToSender = (HttpWebRequest)WebRequest.Create("http://www.senderdomain.com/sender.aspx?cmd=getvalue");
        HttpWebResponse responseFromSender = (HttpWebResponse)requestToSender.GetResponse();
        string fromSender = string.Empty;

        //Remember to use System.IO namespace
        using (StreamReader responseReader = new StreamReader(responseFromSender.GetResponseStream()))
        {
            fromSender = responseReader.ReadToEnd();
        }
        Response.Write(fromSender);
        Response.End();
    }
}

And in the sender.aspx

//On Page_Load of sender.aspx 
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["cmd"].ToString()))
        {
            string cmd = Request.QueryString["cmd"].ToString();
            if (cmd.Equals("getvalue", StringComparison.OrdinalIgnoreCase))
            {
                Response.Clear();
                Response.Write("Hello");
                Response.End();
            }
        }

        Response.Redirect("http://www.receiverdomain.com/receiver.aspx");
        Response.End();
    }
}

Solution 2

pass data in query string because can not do like this

for example

   Response.Redirect(Request.UrlReferrer.ToString() + "?mytext=hello");

And in receiver page access querystring data, will resolve your issue.

use private algorithm like 

 string message = "hello";
 add 1 to each char so that hello become ifmmp

and on receiver side -1 from each char so it will be hello 

Solution 3

You need to pass the value in the url or post it in a cross page postback.

For secure cross domain communication, take a look at SAML (Security Assertion Markup Language). It is a standard way of passing information securely across domain boundaries. It is most often used in Single Sign On scenarios, but it can be used to pass data securely. Are you using certificates? What type of encryption are you using?

Another option would be to save state to a database or filesystem that is accessible to both domains.

Share:
10,054
Gopi
Author by

Gopi

!?!?!?!?

Updated on June 04, 2022

Comments

  • Gopi
    Gopi almost 2 years

    I have a page www.senderdomain.com/sender.aspx, from which i need to write a string to another page in other domain www.receiverdomain.com/receiver.aspx

    In sender.aspx i have written

    Response.Write("Hello");
    Response.Redirect(Request.UrlReferrer.ToString());
    

    It gets redirected to respective receiver.aspx page, but I am not sure how to get the text "Hello" in receiver.aspx page. Can any pl help on this?