SignalR Context.User.Name returns empty

2019-05-10 05:21发布

问题:

Whenever I try to access Context.User.Identity from a Hub, the user details are always empty.

Note: Context.User does not return null, the properties are just empty:

I've taken a look at a multitude of questions on SO similar to this, but all of them seem to be asking why the Context.User is null, and the answer is to move app.MapSignalR(); below ConfigureAuth();, as I have done:

    public void Configuration(IAppBuilder app)
    {
        ConfigureAuth(app);
        app.MapSignalR();
    }

The HttpContext.Current.User also returns empty, but again, only from within a Hub. If I call it from any other Controller, I get the currently logged in user details.

Finally, I also find it disturbing that HttpContext.Current.User.IsAuthenticated is false, yet the user can still access the function. (See the Authorize attribute in the screenshot above.)

Is anybody able to shed some light as to why my user is empty?

All help is greatly appreciated.

回答1:

Set anoynomous to false and windows authentication to true