Skip to content

Instantly share code, notes, and snippets.

@jinan-kordab
Created July 2, 2018 07:35
Show Gist options
  • Save jinan-kordab/c341b5551add549b679770b17eadda13 to your computer and use it in GitHub Desktop.
Save jinan-kordab/c341b5551add549b679770b17eadda13 to your computer and use it in GitHub Desktop.
Admin page part of client side access for SignalR example
<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="WebApplication2.Admin" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<!--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>
<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) {};
//Start the connection
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
chat.server.send($(".allLoggedInUsers option:selected").text().split('|')[0].toString(), $('#message').val());
});
});
});
</script>
<div class="row">
<h1>Admin Page<sup><a href="https://thoughtsonprogramming.wordpress.com/">thoughtsonprogramming.wordpress.com</a></sup></h1>
</div>
<div class="row">
<div class="col-md-6">
<select runat="server" multiple id="allLoggedInUsers" class="allLoggedInUsers" style="width:100%;max-width:100%; border: none; background-color: lightgray">
</select>
</div>
<div class="col-md-6">
<input type="text" id="message" style="width: 100%; height: 67px" />
<input type="button" id="sendmessage" value="Send" style="width: 250px; height: 67px" />
</div>
</div>
</asp:Content>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment