Skip to content

Instantly share code, notes, and snippets.

@jinan-kordab
Created July 2, 2018 07:28
Show Gist options
  • Save jinan-kordab/4c60638c0608a23f3c53d16e9a8c1d32 to your computer and use it in GitHub Desktop.
Save jinan-kordab/4c60638c0608a23f3c53d16e9a8c1d32 to your computer and use it in GitHub Desktop.
Client part Default.aspx page for SignalR example
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="583675786996-cvrblhj6p7n4rc7t4pjb7t5jragdnh6g.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.2.3.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="http://localhost:8080/signalr/hubs"></script>
<!--Add script to update the page and send messages.-->
<script type="text/javascript">
$(function () {
//Set the hubs URL for the connection
$.connection.hub.url = "http://localhost:8080/signalr";
// Declare a proxy to reference the hub.
var chat = $.connection.myHub;
// Create a function that the hub can call to broadcast messages.
chat.client.addMessage = function (name, message) {
callNotify(message);
};
// Start the connection.
$.connection.hub.start().done(function () {
$('#connectionidfield').val($.connection.hub.id);
//console.log('Now connected, connection ID=' + $.connection.hub.id);
});
});
function callNotify(m) {
$.notify(m, { type: "success", blur: 0.2, delay: 0 });
}
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
var ID = profile.getId();
var FullName = profile.getName();
var GivenName = profile.getGivenName();
var FamilyName = profile.getFamilyName();
var Email = profile.getEmail();
var GoogleTokenID = id_token;
var UserConnectionID = $('#connectionidfield').val();
//Ajax call server side update
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url:'<%= ResolveUrl("Default.aspx/BindDatatable") %>',
data: '{uniqueUserID:"'+ UserConnectionID +'",fullName:"' + FullName + '",givenName:"' + GivenName + '",familyName:"' + FamilyName + '",email:"' + Email + '",googleToken:"'+GoogleTokenID+'"}',
dataType: "json",
success: function (data) {
//alert(data.d);
},
failure: function(r) {
alert(r.d);
},
error: function(response) {
alert(response.d);
}
});
};
</script>
<header class="bg-primary text-white">
<div class="container text-left">
<h1>SignalR example</h1>
<p class="lead">If you want, you can log in with google to proceed<br />
<sub><a href="https://thoughtsonprogramming.wordpress.com/">thoughtsonprogramming.wordpress.com</a></sub>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
</p>
<input type="hidden" id="connectionidfield" />
</div>
</header>
</asp:Content>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment