簡體   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