Click here to Skip to main content
13,000,469 members (56,830 online)
Rate this:
Please Sign up or sign in to vote.
i want to send the server event(push notificaton) to specific users(based on their usernames) any idea how to do it?
Posted 16-Jun-12 8:19am
Updated 16-Jun-12 21:46pm
Not clear....
agha_ali22 17-Jun-12 3:13am
i have an aspx page which send notification to connected clients (connected by Html5 event source) and now i wanted to send notification to a specific username which i have saved in session or in some scenario i want to send notification to a group which is also saved in session as groupid(admin(1),manager(2),e.t.c)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

HTTP works in disconnected mode. The server does not remember its clients.

You should implement server polling from client side scripting[^][^][^]
agha_ali22 18-Jun-12 5:24am
what i want is to notify a group of clients that something happened , now i can notify all the connected clients what i want is notify a group

Here is the Default.aspx file<script type="text/javascript">

window.onload = function () {
if (window.EventSource == undefined) {
document.getElementById('targetDiv').innerHTML = "Your browser doesn't support Server Side Events.";
var source = new EventSource('SSEHandler.aspx');

source.onopen = function (event) {
document.getElementById('targetDiv').innerHTML += 'Connection Opened.<br>';

source.onerror = function (event) {
if (event.eventPhase == EventSource.CLOSED) {
document.getElementById('targetDiv').innerHTML += 'Connection Closed.<br>';

source.onmessage = function (event) {

<div id="targetDiv">

and here is 'SSEHandler.aspx' cs

protected void Page_Load(object sender, EventArgs e)

Response.ContentType = "text/event-stream";

while (true)

Response.Write(string.Format("data: {0}\n\n","Hello"));

now i want to send the response to the desired user. this can be done by long pooling but i want to do with html5 Server sent event any idea?
The reverse is not possible because of the stateless architecture of the HTTP. Polling is the only option as far as I know..
agha_ali22 18-Jun-12 6:40am
Server Side Events is a more basic way to send one way data from the server to the client. It works like a long request from the clients JavaScript function where data can is returned bit by bit during the response and each time a bit is returned a JavaScript event is triggered.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

SSE broadcasts to all open connections. Include your group in your JSON stream and do the group check in the javascript.

Note : This is not a secure method, do not use sensitive data this way, since everyone gets every single message, it'll only be handled by your javascript differently.

Example :

Server-Side C#
string JSON = "data: {'IntendedFor' = 'AdminClerks', 'Message' = 'You\'ve got a server event'}";

Client HTML
<input id='myGroup' type='hidden' value='AdminClerk' />

Client Javascript
var myGroup = document.GetElementById('myGroup').value;
var source = new EventSource('<insert url="" here="">');
source.onmessage = function (e) {
  var myJSONResponse = JSON.parse(;
  if (myJSONResponse.IntendedFor == myGroup)
    alert("You've got a server event");
agha_ali22 16-Apr-13 12:25pm
Now I am using SignalR which exactly do what i want,but as my question was concerned your answer is correct
D Hinterlang 17-Apr-13 3:40am
I'm also using SignalR :) Really awesome framework for doing exactly this sort of thing.

Thanks for solution accept :) It's how I was doing it before I moved to SignalR.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 4 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100