本文整理汇总了C#中IRequest.GetHttpContext方法的典型用法代码示例。如果您正苦于以下问题:C# IRequest.GetHttpContext方法的具体用法?C# IRequest.GetHttpContext怎么用?C# IRequest.GetHttpContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRequest
的用法示例。
在下文中一共展示了IRequest.GetHttpContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUserId
public string GetUserId(IRequest request)
{
ApplicationUserManager userManager = request.GetHttpContext().GetOwinContext().GetUserManager<ApplicationUserManager>();
if (request.User == null)
return "";
var user = userManager.FindByName(request.User.Identity.Name);
return user.Id.ToString();
}
示例2: AuthorizeHubConnection
public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request)
{
var token = request.QueryString.Get("Bearer");
var authenticationTicket = Startup.AuthServerOptions.AccessTokenFormat.Unprotect(token);
if (authenticationTicket == null || authenticationTicket.Identity == null || !authenticationTicket.Identity.IsAuthenticated)
{
return false;
}
request.Environment["server.User"] = new ClaimsPrincipal(authenticationTicket.Identity);
request.Environment["server.Username"] = authenticationTicket.Identity.Name;
request.GetHttpContext().User = new ClaimsPrincipal(authenticationTicket.Identity);
return true;
}
示例3: AuthenticateToken
private bool AuthenticateToken(HttpContext context, IRequest request)
{
var tokenValue = context.Request.QueryString.Get("auth-token");
if (tokenValue != null)
{
UserDto user = Services.Users.GetUserbyToken(tokenValue);
if (user != null)
{
var identity = new ClaimsIdentity(DefaultAuthenticationTypes.ExternalCookie);
identity.AddClaim(
new Claim(ClaimTypes.Name, user.UserName)
);
request.Environment["server.User"] = new ClaimsPrincipal(identity);
request.Environment["server.Username"] = identity.Name;
request.GetHttpContext().User = new ClaimsPrincipal(identity);
return true;
}
}
return false;
}