当前位置: 首页>>代码示例>>C#>>正文


C# IRequest.GetHttpContext方法代码示例

本文整理汇总了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();
 }
开发者ID:omeralper,项目名称:myApp,代码行数:8,代码来源:ChatHub.cs

示例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;
        }
开发者ID:ankitvijay,项目名称:AngularJSAuthentication,代码行数:15,代码来源:QueryStringBearerAuthorizeAttribute.cs

示例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;
 }
开发者ID:nguyenminhthu,项目名称:TeleConsult,代码行数:20,代码来源:SignalRAuthorize.cs


注:本文中的IRequest.GetHttpContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。