Asp.net Gmail İle Login Olmak
20 Haziran 2022 / 08:51
Burak
Merhabalar,
Asp.net ‘de gmail yani google hesabınızı kullanarak üye girişi veya login alanı yapmak isterseniz. Burdan direk örnek kodu indirebilirsiniz.Kodlaması ise aşağıdaki gibidir.
Html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="btnLogin" Text="Login" runat="server" OnClick="Login" /> <asp:Panel ID="pnlProfile" runat="server" Visible="false"> <hr /> <table> <tr> <td rowspan="6" valign="top"> <asp:Image ID="ProfileImage" runat="server" Width="50" Height="50" /> </td> </tr> <tr> <td> ID: <asp:Label ID="lblId" runat="server" Text=""></asp:Label> </td> </tr> <tr> <td> Name: <asp:Label ID="lblName" runat="server" Text=""></asp:Label> </td> </tr> <tr> <td> Email: <asp:Label ID="lblEmail" runat="server" Text=""></asp:Label> </td> </tr> <tr> <td> Verified Email: <asp:Label ID="lblVerified" runat="server" Text=""></asp:Label> </td> </tr> <tr> <td> <asp:Button Text="Clear" runat="server" OnClick="Clear" /> </td> </tr> </table> </asp:Panel> </div> </form> </body> </html> |
Codebehind tarafı
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text; using System.Net; using System.IO; using ASPSnippets.GoogleAPI; using System.Web.Script.Serialization; public partial class CS2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { GoogleConnect.ClientId = "<Google Client ID>"; GoogleConnect.ClientSecret = "<Google Client Secret>"; GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0]; if (!this.IsPostBack) { if (!string.IsNullOrEmpty(Request.QueryString["code"])) { string code = Request.QueryString["code"]; string json = GoogleConnect.Fetch("me", code); GoogleProfile profile = new JavaScriptSerializer().Deserialize<GoogleProfile>(json); lblId.Text = profile.Id; lblName.Text = profile.Name; lblEmail.Text = profile.Email; lblVerified.Text = profile.Verified_Email; ProfileImage.ImageUrl = profile.Picture; pnlProfile.Visible = true; btnLogin.Enabled = false; } if (Request.QueryString["error"] == "access_denied") { ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true); } } } protected void Login(object sender, EventArgs e) { GoogleConnect.Authorize("profile", "email"); } protected void Clear(object sender, EventArgs e) { GoogleConnect.Clear(Request.QueryString["code"]); } public class GoogleProfile { public string Id { get; set; } public string Name { get; set; } public string Picture { get; set; } public string Email { get; set; } public string Verified_Email { get; set; } } } |
Bir sonraki konuda görüşünceye kadar bol sorgulu günler 🙂
Etiketler: asp.net google ile login olmak, asp.net google ile üye girişi, asp.net webforms gmail login, asp.net webforms google ile login olmak
Bu Yazılarıda Okuyabilirsiniz...
Bir cevap yazın