Accepting ASP.NET Forms Authentication cookies in

2019-04-28 16:43发布

I've got an self-hosted SignalR instance, using OWIN. I'd like to implement authorization. My users will already have logged into an ASP.NET MVC application, using Forms Authentication.

Since the two applications will be available at the same URL, the cookies will be shared between the two. How do I accept a Forms Authentication cookie in a self-hosted SignalR application?

Clarification: I'm talking about a browser accessing a self-hosted SignalR hub using the same credentials that were used to log into a separate (but related, and installed on the same host) IIS application.

So, the question is: how do I hook into the SignalR server pipeline to capture the .ASPXAUTH cookie and use it to set the current principal before calling the hub?

If it helps, I can throw some Nancy into the mix.

1条回答
看我几分像从前
2楼-- · 2019-04-28 17:26

If your user is already authenticated and logged in, you can check the following within your SignalR hub:

Context.User.Identity.IsAuthenticated

Assure this property is set to true. You can place this check within the constructor of your hub to block/remove their connection. If false, you can redirect them to another page.

查看更多
登录 后发表回答