ASP.NET - Response.Redirect 未填充 Url Referrer
我觉得我已经这样做了很多次了,但我一生都无法弄清楚出了什么问题。
Default.aspx:
protected void Page_Load(object sender, EventArgs e)
{
var r1 = Request.UrlReferrer; // null
var r2 = Request.ServerVariables["HTTP_REFERRER"]; // null
}
SingleSignOn.aspx:
protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("/");
}
如果我在 URL 中输入“/SingleSignOn.aspx”,它会重定向到 Default.aspx,但引荐来源网址为空。
我在这里缺少什么?
我想要做的(这是一个简化的示例),在任何页面上,我都会有一些 JavaScript 来执行以下操作:
window.location.replace('~/SingleSignOn.aspx');
您猜对了,它使用户登录,并重定向到主页。
但我需要在 JavaScript 中构建逻辑,以便在我们刚从那里访问时不会重定向到 SingleSignOn.aspx 页面。
引荐来源网址是否仅由实际链接用户点击填充?
那我该怎么做呢?我不想使用 QueryString 因为我不想在 URL 中看到它。
我能想到的唯一其他选择是会话。
请帮忙。 =(
I feel like i've done this a ton of times, but i can't for the life of me figure out what is going wrong.
Default.aspx:
protected void Page_Load(object sender, EventArgs e)
{
var r1 = Request.UrlReferrer; // null
var r2 = Request.ServerVariables["HTTP_REFERRER"]; // null
}
SingleSignOn.aspx:
protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("/");
}
If i type "/SingleSignOn.aspx" in the URL, it redirects to Default.aspx, but the referrer is null.
What am i missing here?
What im trying to do (this is a simplified example), is on any page, i will have some JavaScript to do the following:
window.location.replace('~/SingleSignOn.aspx');
Which, you guessed it, signs the user in, and redirects to the homepage.
But i need to build logic into that JavaScript to not redirect to the SingleSignOn.aspx page if we just came from there.
Does the referrer only get populated by actual link user clicks?
How can i do this then? I don't want to use QueryString because i dont want to see that in the URL.
The only other option i can think of is Session.
Please help. =(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
虽然已经很晚了,但当你管理响应时。重定向内容,您可以将查询参数用作
response.redirect("/?url=home.aspx&q=whatever")
。然后您可以在页面加载或初始化时捕获它并采取适当的操作
It's pretty late but as you manage response. redirect content, you could use query parameters as
response.redirect("/?url=home.aspx&q=whatever")
.Then you can capture it when page load or init and take the proper action about
只是一种预感,但请尝试使用绝对 url 来代替/甚至包括 http:// 部分。
也就是说,您不应该依赖 UrlReferrer 的存在,因为它可以从客户端剥离(通过插件,甚至不确定是否通过某些浏览器配置)。
Just a hunch, but try using an absolute url instead / including even the http:// part.
That said, you shouldn't rely on the UrlReferrer from being there, as it can be stripped off from the client side (by addins, not sure if even by some browser configs).
所以,我做了一些谷歌搜索来找到我的答案。
不感谢 Stack Overflow - 开玩笑,=)
因此 URL Referrer 仅由实际的客户端点击(锚标记、按钮)填充。
当您手动将其放入 URL 时(这就是我的 JavaScript 所做的),则不会。
我要做的解决方案是在 SingleSignOn.aspx 页面上创建一个 cookie,并在再次重定向之前从 JavaScript 读取该 cookie。
正是我需要的,更多饼干。 =(
除非这里有人有更好的主意,否则我们就会这么做。
So, i've done some Google'ing to find my answer.
No thanks to Stack Overflow - kidding, =)
So the URL Referrer is only populated by an actual client-click (anchor tag, button).
Not when you manually put it in the URL (which is what my JavaScript is doing).
The solution i am doing to have to with is to create a cookie on the SingleSignOn.aspx page, and read that cookie from the JavaScript before i redirect again.
Just what i need, more cookies. =(
Unless someone here has a better idea, that's what ill be going with.