Response.Redirect的页眉 [英] Response.Redirect with headers

查看:109
本文介绍了Response.Redirect的页眉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置页眉和重定向到不同的网页这样的 -

  Response.Headers.Add(ID,TESTTEST);
的Response.Redirect(http://www.somesite.com/somepage.aspx);

而在的Page_Load SomePage.aspx页面的,我检查头的要求 -

 如果(!string.IsNullOrEmpty(请求[ID))
{
   //做一些事情身份证
}

请求[身份证]总是空。我如何在新的页面标题的价值?我不希望使用的查询字符串。

谢谢!

更新:

下面是更详细一点 - 我有两个不同计算机上运行的两个ASP.NET v4的Web应用程序(Site 1和Site 2)。站点1只有一个ASPX的形式,它只有一个按钮就可以了。在按一下按钮,我打的数据库,并得到我需要的,应该把它传递到站点2.在站点2的Global.asax中的价值,我会阅读从站点1接收的头信息,并使用的值。

更新#2:

我能得到它的工作 -

 的Response.Write(
                    的String.format(
                        @<形式的行动={0}ID =测试方法=POST><输入类型=隐藏的名字='关键'值= {1} />< /表>
                  <脚本类型=文/ JavaScript的'>
                     的document.getElementById(测试)提交()。
                  < / SCRIPT>
                        http://www.somesite.com,1234));

在目标网站,我是能够得到使用值 -

 请求[钥匙]


解决方案

HTTP头仅适用于当前的响应。当您设置一个重定向当前响应包含您的自定义标题,但是当浏览器遵循重定向位置的头不再present。此外,您使用的是请求[身份证] 中的其他页面,所以你需要发送的值作为查询字符串:

 的Response.Redirect(http://www.somesite.com/somepage.aspx?id=test);

I'm trying to set the headers and redirecting to a different page like this -

Response.Headers.Add("id", "testtest");
Response.Redirect("http://www.somesite.com/somepage.aspx");

And in the page_load of somepage.aspx, I'm checking the request for headers -

if (!string.IsNullOrEmpty(Request["id"]))
{
   // do something with "id"
}

But Request["id"] is always null. How do I get the values of the header in the new page? I do not want to use query strings.

Thanks!

Update:

Here's a little more detail -- I have two ASP.NET v4 web applications (Site 1 and Site 2) running on two different machines. Site 1 has just one aspx form and it has only one button on it. On button click, I hit the database and get the value I need and should pass it on to Site 2. In the Global.asax of Site 2, I'll be reading the header information received from Site 1 and use the value.

Update #2:

I was able to get it to work --

 Response.Write(
                    string.Format(
                        @"<form action='{0}' id='test' method='POST'><input type='hidden' name='key' value={1} /></form>
                  <script type='text/javascript'>
                     document.getElementById('test').submit();
                  </script> ",
                        "http://www.somesite.com", "1234"));

In the destination site, I was able to get the value using -

Request["key"]

解决方案

HTTP headers are valid only for the current response. When you set a redirect the current response contains your custom header but when the browser follows the redirect location those headers are no longer present. Furthermore you are using Request["id"] in the other page so you need to sent the value as query string:

Response.Redirect("http://www.somesite.com/somepage.aspx?id=test");

这篇关于Response.Redirect的页眉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆