Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在谷歌登录后重定向到另一个页面?_C#_Asp.net_Login_Google Login - Fatal编程技术网

C# 如何在谷歌登录后重定向到另一个页面?

C# 如何在谷歌登录后重定向到另一个页面?,c#,asp.net,login,google-login,C#,Asp.net,Login,Google Login,我使用谷歌登录作为我的SSO,但当我成功使用谷歌登录时,它会将我重定向回我的登录页面。使用谷歌登录后,我如何将它重定向到我的主页 if (!string.IsNullOrEmpty(Request.QueryString["code"])) { string code = Request.QueryString["code"]; string json = GoogleConnect.Fetch("me", code

我使用谷歌登录作为我的SSO,但当我成功使用谷歌登录时,它会将我重定向回我的登录页面。使用谷歌登录后,我如何将它重定向到我的主页

        if (!string.IsNullOrEmpty(Request.QueryString["code"]))
        {
            string code = Request.QueryString["code"];
            string json = GoogleConnect.Fetch("me", code);
            GoogleProfile profile = new JavaScriptSerializer().Deserialize<GoogleProfile>(json);
            Label1.Text = profile.Id;
            Label2.Text = profile.DisplayName.ToString();
            Label3.Text = profile.Emails.Find(email => email.Type == "account").Value;


            Image1.ImageUrl = profile.Image.Url;
            ImageButton1.Visible = false;
        }
        if (Request.QueryString["error"] == "access_denied")
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
        }
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        GoogleConnect.Authorize("profile", "email");

    }
if(!string.IsNullOrEmpty(Request.QueryString[“code”]))
{
字符串代码=Request.QueryString[“code”];
字符串json=GoogleConnect.Fetch(“我”,代码);
GoogleProfile=newJavaScriptSerializer()。反序列化(json);
Label1.Text=profile.Id;
Label2.Text=profile.DisplayName.ToString();
Label3.Text=profile.Emails.Find(email=>email.Type==“account”).Value;
Image1.ImageUrl=profile.Image.Url;
ImageButton1.可见=假;
}
if(Request.QueryString[“error”]=“访问被拒绝”)
{
RegisterClientScriptBlock(this.GetType(),“警报”,“警报('Access denied')”,true);
}
}
受保护的无效ImageButton1\u单击(对象发送者,ImageClickEventArgs e)
{
GoogleConnect.Authorize(“个人资料”、“电子邮件”);
}

您需要在google认证api中传递回调url。回调后,将调用提供的url,并执行定义的方法。在该方法中,您将获得要验证的用户信息和令牌。之后,您可以重定向到主页。

您需要在google认证api中传递回调url。回调后,将调用提供的url,并执行定义的方法。在该方法中,您将获得要验证的用户信息和令牌。之后,您可以重定向到您的主页。

谷歌回调会给您发送成功或错误消息。如果您获得了成功标志,您将获得一个包含用户数据的数组。使用这些数据,您需要设置会话。所以你不会回到你的登录页面。或者,当您调用GoogleAPI时,您没有为应用程序设置正确的回调

谷歌回调给你成功或错误信息。如果您获得了成功标志,您将获得一个包含用户数据的数组。使用这些数据,您需要设置会话。所以你不会回到你的登录页面。或者,当您调用GoogleAPI时,您没有为应用程序设置正确的回调

如果您没有在查询字符串中获得令牌,您可以验证它,然后将其重定向到主页。我只获得了刷新令牌。如何获取访问令牌?它的哪一部分显示了检索访问令牌的部分?Sorry我没有代码,但我在两周前做了同样的事情,发送令牌并获取访问令牌(将在3600秒=1小时后过期)如果您没有在查询字符串中获取令牌,您可以验证它,然后将其重定向到主页我只获得了刷新令牌。如何获取访问令牌?它的哪一部分显示了检索访问令牌的部分?对不起,我没有代码,但我在两周前做了同样的事情,发送令牌并获取访问令牌(3600秒后到期=1小时)