SignalR: “The user identity cannot change during an active SignalR connection” error with windows auth website

大憨熊 提交于 2019-12-10 13:15:44

问题


I have an MVC 5 website running signalR 2.1.0 using Windows Authentication. Because I'm using windows auth login/logout is handled automatically by IIS. Occassionally I'm getting a 403 error saying "Unrecognized user identity. The user identity cannot change during an active SignalR connection." This doesn't happen all the time, and I can't seem to find a pattern to when it does and does not work. Has anyone else encountered this?

Here is the code on the view:

<script type="text/javascript">
        $(document).ready(function() {
            SignalRSetup();
        });

        function SignalRSetup() {
            // Declare a proxy to reference the hub.
            var hub = $.connection.tokenRequestHub;

            // Create a function that the hub can call to broadcast messages.
            hub.client.updateFromService = function(tokenRequestID, message, success) {
                var msg = "Token Request ID {0} => {1}".format(tokenRequestID, message);
                var notyType = (success) ? 'success' : 'error';
                noty({ text: msg, type: notyType, timeout: 2000 });
                if (success) {
                    refreshGrids();
                }
            };

            $.connection.hub.start();//this is where it errors!
        }
</script>

Any help would be greatly appreciated.


回答1:


I think I fixed the issue by adding an [Authorize] attribute to my Hub class. It's only been a few hours, but my SignalR powered page is behaving much better.




回答2:


What worked for me was to disable Anonymous Authentication in the IIS settings.




回答3:


Another solution I found other than disable Anonymous Authentication is to add

GlobalHost.HubPipeline.RequireAuthentication();

to public void Configuration(IAppBuilder app) method in the Startup class.



来源:https://stackoverflow.com/questions/25046648/signalr-the-user-identity-cannot-change-during-an-active-signalr-connection-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!