logo
down
shadow

Managing SignalR connections for Anonymous user


Managing SignalR connections for Anonymous user

By : Tio Google
Date : November 22 2020, 10:48 AM
I wish this help you Use Forms Authentication, store a Federated Cookie and store the hub region in the cookie as well.. In SignalR jQuery code, use a jQuery plugin to read HTTP cookie and get the region name and subscribe to notifications.
Alternatively, in your .cshtml, render jQuery with region populated from your View Model.
code :


Share : facebook icon twitter icon
Managing Shared Unsubscribing in SignalR and Rx

Managing Shared Unsubscribing in SignalR and Rx


By : Spirol04
Date : March 29 2020, 07:55 AM
this will help .Publish().RefCount() does exactly what you are describing. Just make sure you use the same observable for each subscription or the ref counting won't work.
SignalR exception "Unrecognized user identity. The user identity cannot change during an active SignalR connection.

SignalR exception "Unrecognized user identity. The user identity cannot change during an active SignalR connection.


By : Sanjeev
Date : March 29 2020, 07:55 AM
I wish this helpful for you I was corresponding with David Fowler (the author of SignalR) on Github and he said there wasn't an easy way of resolving this.
To get around the problem, I implemented a Silent Logout controller action, which simply kills the users session.
code :
    [HttpPost]
    [AjaxOnly]
    public ActionResult SilentLogOff()
    {
        _unitOfWork.WebSecurity.Logout();

        return Json(new
        {
            IsSuccess = true,
        });
    }
SetLogoutTimer: function () {

    var formsTimeoutValue = $("#hdnRefreshTimeout").val();

    clearTimeout("formsTimeoutTimer");

    var formsTimeoutTimer = setTimeout(function () {
        $.connection.hub.stop();

        AppName.Authenticated.SilentLogoutUser();

    }, formsTimeoutValue);
}

SilentLogoutUser: function() {
    var url = $("#logout a").attr("data-bind-silent-url");
    $.ajax({
        type: "POST",
        url: url,
        success: function (response) {
            if (response.IsSuccess === true) {
                window.location.reload(true);
            }

        }
    });
}
SignalR - Send message to All, Excluding a user's all connections

SignalR - Send message to All, Excluding a user's all connections


By : Tomáš Mrázek
Date : March 29 2020, 07:55 AM
Any of those help You should change your Groups collection to use the name as the key and a List as value.
Then change your OnConnected() override to look for the name key and add or create the List of connectionId.
code :
List<string> clientWindows; 
Groups.TryGetValue(name, out clientWindows); 
clientWindows.ForEach(connectionId => {
    Clients.Client(connectionId)
         .broadcastNotification(username, page, type, id, title);
});
var others = Groups.Where(n => n.Key != name).SelectMany(s => s.Value);
Clients.AllExcept(others.ToArray())
    .broadcastNotification(username, page, type, id, title);
Dictionary<string, List<string>> Groups = new Dictionary<string, List<string>>()
using System.Collections.Generic;
using System.Linq;

private static Dictionary<string, List<string>> userGroups 
                                 = new Dictionary<string, List<string>>()
private static object _lock = new object();

public class NotificationHub : Hub
{
    public void ShowSelfNotification(string page, string type, int id, string title)
    {
        string username = Context.User.Identity.Name;
        Clients.Group(username).broadcastNotification(page, type, id, title);
    }

    public void ShowNotification(string page, string type, int id, string title)
    {
        string username = Context.User.Identity.Name;
        var others = userGroups.Where(n => n.Key != username)
                               .SelectMany(s => s.Value);

        Clients.AllExcept(others.ToArray())
               .broadcastNotification(username, page, type, id, title);
    }

    public override Task OnConnected()
    {
        string name = Context.User.Identity.Name;
        Groups.Add(Context.ConnectionId, name);

        lock(_lock)
        {
            if (userGroups .ContainsKey(name))
                userGroups [name].Add(Context.ConnectionId);
            else
                userGroups .Add(name, new List<string>{Context.ConnectionId})

        }

        return base.OnConnected();
    }

   public override Task OnDisconnected()
   {
       string name = Context.User.Identity.Name;
       lock(_lock)
       {
            if (userGroups .ContainsKey(name))
                userGroups[name].Remove(Context.ConnectionId);
       }
       return base.OnDisconnected();
   }
}
SignalR C# MVC Mapping Anonymous User to Client ID

SignalR C# MVC Mapping Anonymous User to Client ID


By : Sameer Khan
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , a solution widely adopted is to make the user register with his some kind of id with connection back , on the onConnected.
code :
 public override Task OnConnected()
        {
            Clients.Caller.Register();


            return base.OnConnected();
        }
 public void Register(Guid userId)
    {
        s_ConnectionCache.Add(userId, Guid.Parse(Context.ConnectionId));
    }
static readonly IConnectionCache s_ConnectionCache = new ConnectionsCache();
 public class ConnectionsCache :IConnectionCache
{
    private readonly Dictionary<Guid, UserConnections> m_UserConnections = new Dictionary<Guid, UserConnections>();
    private readonly Dictionary<Guid,Guid>  m_ConnectionsToUsersMapping = new Dictionary<Guid, Guid>();
    readonly object m_UserLock = new object();
    readonly object m_ConnectionLock = new object();
    #region Public


    public UserConnections this[Guid index] 
        => 
        m_UserConnections.ContainsKey(index)
        ?m_UserConnections[index]:new UserConnections();

    public void Add(Guid userId, Guid connectionId)
    {
        lock (m_UserLock)
        {
            if (m_UserConnections.ContainsKey(userId))
            {
                if (!m_UserConnections[userId].Contains(connectionId))
                {

                    m_UserConnections[userId].Add(connectionId);

                }

            }
            else
            {
                m_UserConnections.Add(userId, new UserConnections() {connectionId});
            }
        }


            lock (m_ConnectionLock)
            {
                if (m_ConnectionsToUsersMapping.ContainsKey(connectionId))
                {
                    m_ConnectionsToUsersMapping[connectionId] = userId;
                }
                else
                {
                        m_ConnectionsToUsersMapping.Add(connectionId, userId);
                }
            }

    }

    public void Remove(Guid connectionId)
    {
        lock (m_ConnectionLock)
        {
            if (!m_ConnectionsToUsersMapping.ContainsKey(connectionId))
            {
                return;
            }
            var userId = m_ConnectionsToUsersMapping[connectionId];
            m_ConnectionsToUsersMapping.Remove(connectionId);
            m_UserConnections[userId].Remove(connectionId);
        }



    }
 mChatHub.invoke("Register", PrefUtils.MY_USER_ID).get();
 chat.client.register = function () {
    chat.server.register(SOME_USER_ID);
}
Managing multiple SignalR connections in a single page

Managing multiple SignalR connections in a single page


By : user1384317
Date : March 29 2020, 07:55 AM
I wish this help you Use grouping mechanisme of signalr and NOT create multiple connections for your usecase!
There are limitations from IIS and also from browsers. Some browser have a limit of 4 or 5 paralell connections. You can test it by yourself by opening multiple different browsers.
Related Posts Related Posts :
  • Can we create and access a registry key in HKEY_LOCAL_MACHINE without running application with admin permissions in C#
  • Control light intensity with a UI slider
  • Threading (Does these threads exits or aborts itself?)
  • Change the function of a button if Logged in
  • how to accept value in date format in textbox in C# windows form?
  • remove the lines from RichtextBox?
  • How to call String.Split that takes string as separator?
  • Specify task timeout in parallel linq to objects
  • comparing two custom objects to prevent duplicates
  • How to Print Text from ComboBox into a MessageBox
  • How can I do a Func<object[],Expression<Func<T,bool>>> dynamic?
  • C# SqlDataReader No data exists for the row/column
  • My code is not giving the desired output
  • Is it possible to have multiple MVC routes point to the same controller/view?
  • Updating Listbox results in " Invalid cross-thread access."
  • Finding Elbow Angle with Kinect
  • Host a mvc web api application in the sub-folder of a website
  • How to generate a sequential unique id in a thread-safe way
  • How to add a separator to a WPF combobox that is databound?
  • optimize linq query with related entities
  • Optimize this code for large input
  • Is there any way to clear all list box short way?
  • ACR122 Device Programming sample does not find reader
  • Parallel Library: does a delay on one degree of parallelism delay all of them?
  • How to convert a var which contains Long to an Long[]
  • Quickly prune and create valid data combinations
  • Get 3 parameters out of a Dictionary<string, Dictionary<string Action>>
  • Regex IsMatch taking too long to execute
  • Shuffling divs using C# behindcode
  • ASP.NET Project and IE10 Compatibility Mode issues in Windows 7
  • Why can't I loop through this dictionary?
  • RavenDB Stream for Unbounded Results - Connection Resilience
  • How to remove the focus border of a CheckBox in C# Visual Studio?
  • Exception while using String.Format "Index (zero based) must be greater than or equal to zero and less than the siz
  • Caching an LDAP connection
  • C# How to detect kill event sender
  • How to Display Splashscreen and login form at same time using c#
  • Read .sql script with parameters
  • Why would I need to compile/generate methods/code at runtime?
  • Unable to create a constant value of type 'Project.Models.Subcategory'. Only primitive types or enumeration types are su
  • How to run possibly synchronous or possibly asynchronous code?
  • Drop SQLite tables using list of tables names
  • Can I organize Git submodules in a flat hierarchy?
  • How to make a server reply after receiving a request/data
  • Stored Procedure works in DB but not in C# code
  • MVVM WPF Programmatically add Child Elements
  • NCrunch and PostSharp Logging clash
  • Increasing memory usage in socket client
  • Multiple DropDownList but same action
  • How to get application memory usage as shown in Task Manager?
  • Exposing interfaces instead of concrete classes
  • How to get only postal_code data from google api?
  • Is there a way to get rid of the (by dot42) using community licence?
  • Why must I implement a function for an interface in vb.net which apparently doesn't need to be implemented in C#
  • How to remove HTML tags from the gridview Row
  • Get public post from Facebook's Graph Search API 2.x with Facebook SDK for .NET
  • C# DLL Export to Inno-Setup - Error E0434F4D
  • syntax error insert into database
  • By-pass else block of int.TryParse in Lambda Syntax
  • Retrieve "property getter" from the property name
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org