我一直在研究这一段时间,似乎无法弄清楚。
我有一个需要使用ASP.NET身份验证(MVC5)进行身份验证的.NET SignalR客户端,以便它可以访问使用[授权]属性保护的SignalR集线器。
我找到了以下资源(请参阅.NET客户端/ Cookie的身份验证选项):
http://www.asp.net/signalr/overview/signalr-20/security/hub-authorization
但是,检索cookie的代码示例不起作用,原因是:
authCookie = response.Cookies[FormsAuthentication.FormsCookieName];并且因为我没有使用Forms Authentication,所以会产生一个错误。
我不确定如何改变这个ASP.NET身份?
我关注的是正确的方法,即。 检索一个cookie,然后将其添加到Cookie容器? 或者我应该将标题中的用户名和密码传递给集线器并以某种方式进行验证?
我不知道使用SignalR和Identity Framework使用.NET客户端进行身份验证有多混淆。
即使它不是我的用例,我也用Xamarin标记了这个问题,因为我觉得这也可能是使用SignalR .NET客户端的Xamarin移动开发人员面临的问题。
因为我似乎无法在互联网上找到任何示例,所以我们将非常感谢任何帮助。 谢谢。
I have been researching this for a while and cannot seem to figure it out.
I have a .NET SignalR Client that needs to be authenticated with ASP.NET Identity (MVC5) so that it can access SignalR hubs secured with the [Authorize] attribute.
I found the following resource (Please see Authentication options for .NET Clients / Cookie):
http://www.asp.net/signalr/overview/signalr-20/security/hub-authorization
However the code sample for retrieving the cookie doesn't work due to:
authCookie = response.Cookies[FormsAuthentication.FormsCookieName];and as I am not using Forms Authentication this produces an error.
I am unsure how to change this for ASP.NET Identity?
Am I focused on the correct approach, ie. retrieving a cookie and then adding it to the Cookie Container? or should I be passing the Username and Password in headers to a Hub and authenticating somehow this way?
I did not realise how confusing it would be to authenticate using a .NET client with SignalR and Identity Framework.
Even though it is not my use case I am also tagging the question with Xamarin as I feel this might be an issue faced by Xamarin mobile developers using the SignalR .NET client also.
As I cannot seem to find any examples on the Internet, any assistance would be much appreciated. Thanks.
最满意答案
只需改变这一点
var authCookie = response.Cookies[FormsAuthentication.FormsCookieName];
至
var authCookie = response.Cookies[".AspNet.ApplicationCookie"];
Just change this
var authCookie = response.Cookies[FormsAuthentication.FormsCookieName];
to
var authCookie = response.Cookies[".AspNet.ApplicationCookie"];
更多推荐
发布评论