Merhabalar,
Asp.net ‘de gmail yani google hesabınızı kullanarak üye girişi veya login alanı yapmak isterseniz.
Html
Codebehind tarafı
Asp.net ‘de gmail yani google hesabınızı kullanarak üye girişi veya login alanı yapmak isterseniz.
Html
HTML:
<%@ 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ı
Kod:
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; }
}
}