繁体   English   中英

Google登录后如何重定向到另一个页面?

[英]How to redirect to another page after Google Login?

我使用Google登录名作为我的SSO,但是当我成功使用Google登录名时,它将我重定向回我的登录页面,如何使用Google登录名将其重定向到我的首页?

        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");

    }

您需要在Google身份验证API中传递回调网址。 回调后,将调用提供的url,并执行定义的方法。 通过这种方法,您将获得用户信息和令牌以进行验证。 之后,您可以重定向到您的主页。

谷歌回调给你成功或错误消息。 如果获得成功标志,则会得到一个包含用户数据的数组。 这些数据需要设置会话。 这样您就不会返回登录页面。 否则,当您调用google api时,您尚未为您的应用设置正确的回调。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM