如何判断用户来自哪里?

发布于 2024-08-09 13:30:11 字数 529 浏览 5 评论 0原文

是否有可靠的方法来确定 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

白况 2024-08-16 13:30:11

没有可靠的方法来判断用户来自哪里,这不仅是 ASP.NET 的限制,而且是所有 Web 应用程序的限制。 url 引荐来源网址很容易被欺骗,因此不可靠。我认为最好的选择可能是一些加密的 url 参数,或者 cookie(如果您愿意)。

因此两个页面应该就公共私钥达成一致。

  1. Page1 将使用密钥加密其地址并将其传递给 Page2
  2. Page2 将检查此参数是否存在,并尝试使用用于加密的相同私钥对其进行解密
  3. 如果成功,则意味着 Page2 将能够确定谁调用了是的,如果不是,则数据已被篡改

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.

  1. Page1 will use the key to encrypt its address and pass it to Page2
  2. Page2 will check for the presence of this parameter and try to decrypt it with the same private key used to encrypt
  3. If this succeeds it means that Page2 will be capable to determine who called it, if not, the data has been tampered
嗫嚅 2024-08-16 13:30:11

如果浏览器不传递引用者或使用您所描述的查询字符串,则无法知道。

Without the browser passing a referrer or using the querystring like you describe, there is no way to know.

顾冷 2024-08-16 13:30:11

另一种选择是在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文