如何在aspx页面的页面加载中添加get响应头值。 [英] How do I add get response header value in the page load of an aspx page.

查看:181
本文介绍了如何在aspx页面的页面加载中添加get响应头值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个aspx页面

PageA.aspx

这里我在重定向到PageB.aspx之前设置响应头

I have two aspx pages
PageA.aspx"
Here im setting the response headers before redirecting to PageB.aspx




{
HttpWebRequest htpwebreq = (HttpWebRequest)WebRequest.Create(PageB.aspx);
HttpWebResponse htpwebresp = (HttpWebResponse)htpwebreq.GetResponse();
HttpContext.Current.Response.AddHeader("HeaderName", "HeaderValue");        
Response.Redirect(PageB.aspx);
}





但这些标题值不会出现在PageB中.aspxpageload

page_load代码是:



but these header value is not coming in the "PageB.aspx" pageload
page_load code is:

if(HttpContext.Current != null)
           {
              if (HttpContext.Current.Request.Headers.Get("HeaderName") != null)
                 {

           string  passedValue = Convert.ToString(Request.Headers["HeaderName"]);
                       lblheader.Text = passedValue;
                 }
             else
                 {
                        lblheader.Text = "no value have been returned";
                 }
           }





请帮助我..



我尝试了什么:



i尝试了以下方法,但没有结果。



Kindly assist me on this..

What I have tried:

i have tried below method, but no result.

HttpContext.Current.Response.Write("<BODY Onload=document.forms[0].submit()>");
           HttpContext.Current.Response.Write("    <FORM METHOD='POST' ACTION='" + PageB.aspx+ "'>");
           //HttpContext.Current.Response.Write("  <INPUT TYPE='HIDDEN' NAME='headername' VALUE='" + value + "'>");
           HttpContext.Current.Response.Write("    <INPUT TYPE='HIDDEN' NAME='RelayState' VALUE='" + targetURL + "'>");
           HttpContext.Current.Response.Write("</BODY>");

推荐答案

您可能需要将数据存储在会话或cookie中。重定向只是在响应中添加了额外的标头,告诉浏览器请求重定向到的页面。由于这是触发pageb的请求,因此您从pagea发送的所有标头都将丢失。
You'll probably need to store your data in the Session or a cookie instead. A redirect simply adds additional headers to your response that tells the browser to request the page being redirected to. As this is the request that triggers pageb, all of the headers you sent from pagea are lost.


这篇关于如何在aspx页面的页面加载中添加get响应头值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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