如何使用MVC5 ASP.NET身份验证来验证SignalR .NET客户端(How to authenticate SignalR .NET Client with MVC5 ASP.NET Ide

编程入门 行业动态 更新时间:2024-10-04 19:34:03
如何使用MVC5 ASP.NET身份验证来验证SignalR .NET客户端(How to authenticate SignalR .NET Client with MVC5 ASP.NET Identity Framework)

我一直在研究这一段时间,似乎无法弄清楚。

我有一个需要使用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"];

更多推荐

本文发布于:2023-08-07 13:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464088.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   身份验证   客户端   NET   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!