tem*_*pid 9 asp.net response.redirect
我正在尝试设置标头并重定向到这样的不同页面 -
Response.Headers.Add("id", "testtest");
Response.Redirect("http://www.somesite.com/somepage.aspx");
Run Code Online (Sandbox Code Playgroud)
在page_loadsomepage.aspx中,我正在检查标头的请求 -
if (!string.IsNullOrEmpty(Request["id"]))
{
// do something with "id"
}
Run Code Online (Sandbox Code Playgroud)
但是Request["id"]总是空的.如何在新页面中获取标题的值?我不想使用查询字符串.
谢谢!
更新:
这里有一些细节 - 我在两台不同的机器上运行两个ASP.NET v4 Web应用程序(站点1和站点2).站点1只有一个aspx表单,它只有一个按钮.单击按钮,我点击数据库并获得我需要的值,并将其传递给站点2.在站点2的Global.asax中,我将读取从站点1收到的标题信息并使用该值.
更新#2:
我能够让它工作 -
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"));
Run Code Online (Sandbox Code Playgroud)
在目标网站中,我能够使用 - 获取值 -
Request["key"]
Run Code Online (Sandbox Code Playgroud)
Dar*_*rov 13
HTTP标头仅对当前响应有效.设置重定向时,当前响应包含您的自定义标头,但当浏览器跟随重定向位置时,这些标头不再存在.此外,您正在Request["id"]其他页面中使用,因此您需要将值作为查询字符串发送:
Response.Redirect("http://www.somesite.com/somepage.aspx?id=test");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34564 次 |
| 最近记录: |