none
Using SignalR just for just a user's session RRS feed

  • Question

  • I have a progress bar logic that implements SignalR on a page that processes uploaded file. It works properly and produces correct progress.

    However, it produces progress bar for ALL users, not just for the user that uploaded the file. In other words, one user uploads the file, but that progress for that file upload shows even on screens of other user/sessions that conducted no action on their ends

    I did come up with a workaround, where I send a user id with the SignalR progress call/signal and compare it with the user id stored in a hidden field on aspx. If they don't match, I don't produce the progress bar. However, this fix seems to be like a dirty workaround.

    Is there a more efficient way to ensure the SignalR to work only within one session?

    Just in case here is my code

    hubContext.Clients.All.AddProgress("Currently processing: ", new System.IO.FileInfo(attachment.FileName).Name, "0",
                                Context.User.Identity.Name, pageName);

    My JavaScript

    $(function () {
    
        var progress = $.connection.progressHub;
        console.log(progress);
        var hfUserAccount = document.getElementById("<%=hfUserAccount.ClientID %>");
        // Create a function that the hub can call back to display messages.
        progress.client.AddProgress = function (fileName, message, percentage, userAccount, pageName) {
    
            if (userAccount === hfUserAccount.value && pageName === "CheckEFile.aspx") {
    
                ProgressBarModal("show", fileName + " " + message);
                document.getElementById("divProgress").style.display = "block";
                document.getElementById("divUpload").style.display = "block";
                document.getElementById("divProgress").style.width = percentage + "%";
                document.getElementById("lblPercentage").innerHTML = parseInt(percentage) + "%";
                $("#processingStatus").html("Please Wait. Checking files...");
                $('#ProgressMessage').width(percentage);
                if (percentage === "100%") {
                    ProgressBarModal();
                }
            }
        };
    
    });
    Tuesday, July 16, 2019 9:02 PM

All replies

  • Hi James,

    Welcome to the MSDN forum.

    As far as I know, signlar could send the response to specific user according to connection id. I suggest you could get the connection id and send the response to specific user client.

    Details, you could refer to below codes:

    Clients.Client(connID).SendMessage(name , message);

    Article:

    https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-server

    Best regards,

    Sara


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, July 17, 2019 6:30 AM
  • Thank you for your response. I did come across this suggestion. But, unfortunately it looks like a solution for MVC, not for WebForms as I am unable to get the connection id out of the Context


    Wednesday, July 17, 2019 1:55 PM
  • Hi James,

    Thanks for your update.

    Per your description, please redirect to this appropriate forum: https://forums.asp.net/ for better support, since our forum is to discuss the .NET Framework installation issues, thanks for your understanding.

    If you have any other issues in the future, please feel free to let us know.

    Best regards,

    Sara


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, July 18, 2019 8:16 AM