0

我正在与 vk.com 集成。他们的文档说您将在授权后重定向到下一个 url

http://REDIRECT_URI#access_token= 533bacf01e11f55b536a565b57531ad114461ae8736d6506a3&expires_in=86400&user_id=8492 

并且发生了重定向,但我没有看到 access_token、expires_in 和 user_id 变量。我调查了 HttpContext 并没有找到这些参数。这HttpContext.Request.Url只是显示我的网址,没有#access_token= 533bacf01e11f55b536a565b57531ad114461ae8736d6506a3&expires_in=86400&user_id=8492

但是,如果我将 # 字符替换为 ? 在 url 它按预期工作。

我正在使用来自 ASP.NET MVC 的 vk api。有人知道如何获取这些参数吗?

4

2 回答 2

1

无法读取片段,因为它不会发送到服务器(VK 可能会这样做以提高身份验证过程的安全性)您的选择是使用 JavaScript

<script>
  if(window.location.hash) {
      //Puts hash in variable, and removes the # character
      var hash = window.location.hash.substring(1); 
      // hash found
      alert (hash);
  } else {
      // No hash found
  }
</script>
于 2013-12-04T08:45:59.553 回答
0

遗憾的是,片段没有传递给服务器。

当您尝试从Request.Uri.Fragment.

没有简单的方法可以在服务器上获取片段。您必须使用 javascript 来检索片段并将其发送到服务器可能使用 AJAX 或者您可以创建一个中间页面来读取片段并将用户重定向到另一个页面,片段替换为查询字符串。

中间页面可能是这样的:

if(window.location.hash) {
    window.location= '/yoururl.htm' + window.location.hash.replace('#','?');
}
于 2013-12-04T07:59:43.367 回答