重定向到页面隐藏查询字符串参数asp.net

时间:2014-03-04 19:07:45

标签: c# asp.net response.redirect url-redirection querystringparameter

我正在为一个有Web园景的项目工作,无法在session / inmemory中保存任何数据。 asp.net页面从Appian(bpm工具)打开,我们通过查询字符串传递id。 现在,客户端要求我在读取后隐藏查询字符串参数。但是,在这种情况下,登陆页面为http://a.aspx?id='123',在读取该值后,我们必须重定向到b.aspx而不暴露id(查询字符串)。 请建议我一个合适的方法来实现这一目标。我真的不知道这个。

2 个答案:

答案 0 :(得分:3)

您可以向标题添加键/值对,它在查询字符串中不可见。

HttpContext.Current.Response.Headers.Add( key, value);

string headerVal = HttpContext.Current.Request.Headers[key];

答案 1 :(得分:0)

您可以在服务器端使用会话变量,也可以使用http Post而不是GET。

Session["id"] = id;

在加载b时检索它。

要使用Post,您可以使用隐藏字段和表单。

//You can set it like this
<form name='IdForm' action='b.aspx' method='post'>>
<asp:HiddenField id="WhateverId" runat="server" value='<%= Request.QueryString["whateverID"] %>' />
</form>

在重定向上使用javascript发布

function Redirect() {
     document.forms["IdForm"].submit();
}

您必须在重定向发生的任何地方使用此js脚本。

最后在b.aspx代码后面

HttpContext.Current.Request.Form["WhateverId"]