如何判断用户来自哪里?
是否有可靠的方法来确定 ASP.NET 应用程序中的用户来自何处?我们有一个从两个不同位置链接到的 Web 应用程序。这两个链接位于不同的域上,它们需要规定此应用程序中的某些用户权限。这是我到目前为止所尝试过的...
使用
Request.UrlReferrer
(这是 Referer HTTP 标头)。这总是返回一个空字符串。我相信这是因为超链接使用 JavaScript 来启动弹出窗口。根据我的研究,用户代理在标准超链接上提供此 HTTP 标头。 Javascript 弹出窗口是一个不同的故事(显然)。一个简单的查询字符串来指示引用者。这实际上并不是一个选项,因为我们需要一些不容易绕过的东西(更安全)。
有什么想法吗?我知道,从长远来看,这可以有更好的整体设计/结构。请不要发布建议我重新设计所有内容的答案,因为这不是一个选择。
Is there a reliable way to determine where a user is coming from in an ASP.NET application? We have a web application that is linked to from two different locations. The two links are on separate domains, and they need to dictate certain user permissions within this app. Here's what I have tried so far...
Using
Request.UrlReferrer
(which is the Referer HTTP header). This always returned an empty string. I believe this is because the hyperlinks use Javascript to launch a popup window. Based on my research, the user agent provides this HTTP header on standard hyperlinks. Javascript popups are a different story (evidently).A simple query string to indicate the referrer. This is not really an option because we need something that is not so easy to bypass (more secure).
Any ideas? I understand that in the grand scheme of things, this could have a better overall design/structure. Please don't post an answer suggesting I re-design everything, because that is not an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有可靠的方法来判断用户来自哪里,这不仅是 ASP.NET 的限制,而且是所有 Web 应用程序的限制。 url 引荐来源网址很容易被欺骗,因此不可靠。我认为最好的选择可能是一些加密的 url 参数,或者 cookie(如果您愿意)。
因此两个页面应该就公共私钥达成一致。
There's no a reliable way to tell where an user is coming from and this is not only an ASP.NET limitation, but all web applications in general. The url referrer can be easily spoofed so it is not reliable. I think the best option could be some encrypted url parameter, or cookie if you prefer.
So both pages should agree on common private keys.
如果浏览器不传递引用者或使用您所描述的查询字符串,则无法知道。
Without the browser passing a referrer or using the querystring like you describe, there is no way to know.
另一种选择是在 ASP.NET 应用程序上有两个不同的登录页面。登陆页面可以设置安全选项,然后重定向到公共主页。这比查询字符串选项更安全一些。
或者,您可以在从 ASP.NET 应用程序站点中提取的引用站点上放置一个 1x1 像素图像。应将引荐来源网址传递给脚本,然后您可以在用户计算机上设置一个 cookie,然后您可以在用户访问应用程序主页时引用该 cookie。
Another option is to have two different landing pages on the ASP.NET application. The landing pages can set the security options and then redirect to a common homepage. This is a little more secure than the querystring option.
Or, you could place a 1x1 pixel image on the referring sites that is pulled from your ASP.NET application site. The referrer should be passed to the script and you could then set a cookie on the users machine that you can then reference when they hit the app homepage.