Signalr conflict with Asp.net mvc session

Viewed 21

Im using signal inside my asp.net mvc. im using dotnet4 and the transport is longpolling.

Also im using autofac signalr for dependency injection. The start up for signalr is in

MasterPage js , so every time new page gets open this code will call :

$(document).ready(function () {
    var connection = $.hubConnection("/signalr", { useDefaultPath: false });
    connection.client = function () { };
    var hub = connection.createHubProxy("NotificationHub");
    hub.on("AddMessage", Method);
    connection.start({ jsonp: true })
        .done(function () {
            hub.invoke("FakeLiveState");

            hub.invoke('ConnectionConnectedSaveDB', controllerNameSignalR).done(function () {
            }).fail(function (error) {
            });

        })
        .fail(function (a) {
        });
    connection.disconnected(function () {
        setTimeout(function () {
            connection.start({ jsonp: true })
                .done(function () {
                    hub.invoke('ConnectionConnectedSaveDB', controllerNameSignalR).done(function () {
                    }).fail(function (error) {
                    });

                })
                .fail(function (a) {
                   // console.log('not ReConnected' + a);
                });;
        }, 5000);
    });
    function Method(messageFromHub, callBackUrl) {
        Notification.requestPermission(function (result) {
            if (result === 'granted') {

                if (navigator.userAgent.indexOf("Firefox") > 0) {
                       const options = {
                       body: messageFromHub,
                    };
                    let message = new Notification('test', options);

                    message.onclick = function () {
                        (typeof callBackUrl !== "undefined") ? window.open(callBackUrl) : '';
                    };
                }
                else
                {
                    navigator.serviceWorker.getRegistration().then(registration => {
                        const options = {
                            body: messageFromHub,
                        };

                        if ('showNotification' in registration) {
                            let message = registration.showNotification('test', options);

                            message.onclick = function () {
                                (typeof callBackUrl !== "undefined") ? window.open(callBackUrl) : '';
                            };
                        } else {
                            alert(messageFromHub);
                        }
                    }).catch(() => {
                    });
                } 
            }
        });
    }
});

After opening multiple page i get freeze on all ajax call till the pending of signalr

getting resolved. As mentioned in multiple post this behaviour is normal due to nature

of SessionState. Since im using session for other part of website and depending on it , is

there any to make signalr bypass and not using session ?

like using "[SessionState(SessionStateBehavior.Disabled)]" on hub ?

0 Answers
Related