我有一个MVC 5网站运行signalR 2.1.0使用Windows身份验证。因为我使用的是windows认证,登录/注销由IIS自动处理。偶尔我得到一个403错误说"无法识别的用户身份。在活动SignalR连接期间,用户身份不能更改。"这种情况并不总是发生,我似乎找不到一种模式来说明它什么时候起作用,什么时候不起作用。有人遇到过这种情况吗?
下面是视图的代码:
<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>
我想我通过添加[Authorize]
属性到我的Hub类来修复这个问题。虽然只有几个小时,但是我的SignalR驱动的页面表现得好多了。
对我有效的是在IIS设置中禁用匿名身份验证
我发现除了禁用匿名身份验证之外的另一个解决方案是添加
GlobalHost.HubPipeline.RequireAuthentication();
到Startup
类的public void Configuration(IAppBuilder app)
方法