我有一个Azure WebRole (MVC应用程序)和Azure工人角色。
现在,我的SignalR集线器使用Owin.SelfHost托管在Worker角色中。
MVC应用程序需要在worker角色中调用这个集线器--这是非常简单的。
现在我的问题是身份验证。
我需要访问webrole上的webrole的Context.User.Identity,这样我仍然可以验证对我的集线器的调用。
工作者角色
public class MyHub: Hub
{
public override Task OnConnected() {
var id = Context.User.Identity.Name; // NULL
var connectionId = Context.ConnectionId;
}
[Authorize]
public void SendMessage() ....
}现在-我被困在这里了
public void Configuration(IAppBuilder app)
{
app.Map("/signalr", map =>
{
map.Run(async context =>
{
var userName = context.Request.Query["user"]; //NULL
var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Name, userName));
context.Authentication.SignIn(identity);
});
.....
});
}不知何故,我需要将User.Context (Asp.net identity)从我的WebRole传递给worker角色中的Owin管道。
知道怎么做吗?
发布于 2014-10-21 20:32:06
下面链接的SignalR实现应该回答您的问题。
您可以仔细查看装饰hub类的属性,并查看实现。
您还可以查看集线器类本身中的GetCurrentUserName。
https://github.com/louislewis2/AngularJSAuthentication
路易
https://stackoverflow.com/questions/26018346
复制相似问题