在另一个页面中读取 Response.write

发布于 2024-09-05 10:02:13 字数 361 浏览 3 评论 0原文

我有一个页面 www.senderdomain.com/sender.aspx,我需要从该页面将字符串写入其他域 www.receiverdomain.com/receiver.aspx 中的另一个页面>

在 sender.aspx 中,我已经编写了

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

它被重定向到相应的receiver.aspx 页面,但我不确定如何在receiver.aspx 页面中获取文本“Hello”。任何人都可以帮忙吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

撩起发的微风 2024-09-12 10:02:13

您似乎在 Sender.aspx 上有一个值,需要在receiver.aspx 中显示。您可以这样做。

//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());

编辑

如果域发生更改,直接的简单方法是传递查询字符串中的值。

//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());

您可能会发现代码模式保持不变,并且用于将值从 Session 传输到 QueryString 的容器发生了变化。

EDIT2

如果在这种情况下您担心安全性并且您不希望公开值 ["Hello"],那么这里有另一种方法可以帮助您。在此解决方案中,我们首先将页面重定向到接收者,然后从接收者向发送者询问值。首先我们要编写接收器的代码。

//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();
    }
}

在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();
    }
}

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();
    }
}
扶醉桌前 2024-09-12 10:02:13

您需要传递 url 中的值或将其发布到跨页面回发中。

对于安全的跨域通信,请查看 SAML(安全断言标记语言)。它是跨域边界安全传递信息的标准方法。它最常用于单点登录场景,但它可以用于安全地传递数据。您使用证书吗?您使用什么类型的加密?

另一种选择是将状态保存到两个域均可访问的数据库或文件系统中。

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.

终难愈 2024-09-12 10:02:13

在查询字符串中传递数据,因为不能这样做,

例如

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

在接收器页面访问查询字符串数据,将解决您的问题。

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 

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 
过气美图社 2024-09-12 10:02:13

Response.Redirect 方法将废弃您写入页面的所有内容,并将其替换为重定向页面,因此您无法随重定向一起发送任何内容。

在重定向中发送数据(在不同域和不同服务器之间工作)的唯一选项是将其放入 URL 本身。示例:

string message = "Hello";
Response.Redirect(Request.UrlReferrer.ToString() + "?msg=" + Server.UrlEncode(message));

另一个选项是输出包含自动发布到目标的表单的页面:

string message = "Hello";
Response.Write(
  "<html>" +
  "<head><title>Redirect</title></head>" +
  "<body onload=\"document.forms[0].submit();\">" +
  "<form action=\"" + Server.HtmlEncode(Request.UrlReferrer.ToString()) + "\" method=\"post\">" +
  "<input type=\"hidden\" name=\"msg\" value=\"" + Server.HtmlEncode(message) + "\">" +
  "</form>" +
  "</body>" +
  "</html>"
);
Response.End();

您可以在接收页面上使用 Request.Form["msg"] 来获取值。

The Response.Redirect method will scrap everything that you have written to the page, and replace it with a redirection page, so you can't send any content along with the redirect.

The only option to send data along in a redirect (that works between differnt domains and different servers) is to put it in the URL itself. Example:

string message = "Hello";
Response.Redirect(Request.UrlReferrer.ToString() + "?msg=" + Server.UrlEncode(message));

Another option is to output a page containing a form that is automatically posted to the destination:

string message = "Hello";
Response.Write(
  "<html>" +
  "<head><title>Redirect</title></head>" +
  "<body onload=\"document.forms[0].submit();\">" +
  "<form action=\"" + Server.HtmlEncode(Request.UrlReferrer.ToString()) + "\" method=\"post\">" +
  "<input type=\"hidden\" name=\"msg\" value=\"" + Server.HtmlEncode(message) + "\">" +
  "</form>" +
  "</body>" +
  "</html>"
);
Response.End();

You can use Request.Form["msg"] on the recieving page to get the value.

倾`听者〃 2024-09-12 10:02:13

如果您想避免以后出现各种问题,请不要使用内置的 URL 编码。

    String UrlEncode(String value)
    {
        StringBuilder result = new StringBuilder();

        foreach (char symbol in value)
        {
            if ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~".IndexOf(symbol) != -1) result.Append(symbol);
            else result.Append("%u" + String.Format("{0:X4}", (int)symbol));
        }

        return result.ToString();
    }

上面支持 unicode 以及几乎所有内容。

Don't use the built-in URL encode, if you want to avoid all sorts of problems later.

    String UrlEncode(String value)
    {
        StringBuilder result = new StringBuilder();

        foreach (char symbol in value)
        {
            if ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~".IndexOf(symbol) != -1) result.Append(symbol);
            else result.Append("%u" + String.Format("{0:X4}", (int)symbol));
        }

        return result.ToString();
    }

The above supports unicode, and pretty much everything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文