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


C# HttpContextBase.GetOwinContext方法代码示例

本文整理汇总了C#中System.Web.HttpContextBase.GetOwinContext方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextBase.GetOwinContext方法的具体用法?C# HttpContextBase.GetOwinContext怎么用?C# HttpContextBase.GetOwinContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpContextBase的用法示例。


在下文中一共展示了HttpContextBase.GetOwinContext方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetAuthToken

        public static string GetAuthToken(HttpRequestBase request, HttpContextBase httpContext)
        {
            // Retrieve the user's tenantID and access token since they are used to call the GraphAPI.
            //
            string accessToken = null;
            string tenantId = ClaimsPrincipal.Current.FindFirst(GraphConfiguration.TenantIdClaimType).Value;
            if (tenantId != null)
            {
               accessToken = TokenCacheUtils.GetAccessTokenFromCacheOrRefreshToken(tenantId, GraphConfiguration.GraphResourceId);
            }
            if (accessToken == null)
            {
                //
                // If refresh is set to true, the user has clicked the link to be authorized again.
                //
                if (request.QueryString["reauth"] == "True")
                {
                    // Send an OpenID Connect sign-in request to get a new set of tokens.
                    // If the user still has a valid session with Azure AD, they will not be prompted for their credentials.
                    // The OpenID Connect middleware will return to this controller after the sign-in response has been handled.
                    //
                    httpContext.GetOwinContext().Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationType);
                }
            }

            return accessToken;
        }
开发者ID:jvanzella,项目名称:WebApp-GraphAPI-DotNet,代码行数:27,代码来源:AuthUtils.cs

示例2: AuthorizeCore

        //ver esse esquema de de segurança depois 
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var identity = (ClaimsIdentity)httpContext.User.Identity;

            var url = httpContext.Request.Url.AbsolutePath;
            var value = url.Split('/');
            string[] valueAction = new string[] {};
            if (value.Length == 2) valueAction = new[] {value[1]};
            else if (value.Length == 3) valueAction = new[] {value[1], value[2]};
            else if (value.Length >= 4) valueAction = new[] {value[1], value[2], value[3]};
            
            
            if (!string.IsNullOrWhiteSpace(Action))
            {
                valueAction[valueAction.Length - 1] = Action;   
            }
            url = string.Join("/", valueAction);
            
            var claim = identity.Claims.FirstOrDefault(k => (k.Type.Substring(0,4).Equals("Menu") && k.Value.Contains(url)) || (k.Type.Substring(0, 4).Equals("Inv") && k.Value.Contains(url)));

            if (claim == null) return false;

            var userManager = httpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
            var userId = httpContext.User.Identity.GetUserId();
            var user = userManager.FindById(userId);

            var permissao = user.Permissoes.FirstOrDefault(x => x.AspNetModulo is AspNetAction && ((AspNetAction)x.AspNetModulo).GetUrl() == url);

            if (permissao != null)
                identity.AddClaim(new Claim("AspNet.Identity.Permissao", ((int)permissao.AspNetTipoPermissaoId).ToString()));

            return true;

            
        }
开发者ID:tendenciaconsult,项目名称:RedivivusProd,代码行数:36,代码来源:MenuAuthorizeAttribute.cs

示例3: ServiceBase

 protected ServiceBase(IDataFactory dataFactory, HttpContextBase httpContext)
 {
     DataFactory = dataFactory;
     CurrentUser = httpContext.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
     //            CurrentUser = user ??
     //                           HttpContext.Current.GetOwinContext()
     //                               .GetUserManager<ApplicationUserManager>()
     //                               .FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
 }
开发者ID:panlukz,项目名称:logsol,代码行数:9,代码来源:ServiceBase.cs

示例4: AuthorizeCore

 protected override bool AuthorizeCore(HttpContextBase httpContext)
 {
     UserManager<ApplicationUser> UserManager = httpContext.GetOwinContext().GetUserManager<ApplicationManager>();
     ApplicationUser user = UserManager.FindByName(httpContext.User.Identity.Name);
     if ((user.Banned == true))
     {
         return false;
     }
     return base.AuthorizeCore(httpContext);
 }
开发者ID:Shiloff,项目名称:Project,代码行数:10,代码来源:MyAuth.cs

示例5: GetOperator

 public static Operator GetOperator(HttpContextBase _context)
 {
     var claimsIdentity = _context.GetOwinContext().Authentication.User.Identity as ClaimsIdentity;
     return new Operator()
     {
         UserId = claimsIdentity.GetClaimValue(ClaimTypes.NameIdentifier),
         UserName = claimsIdentity.GetClaimValue(ClaimTypes.Name),
         NickName = claimsIdentity.GetClaimValue(ClaimTypes.Surname),
         Ip = _context.Request.GetIpAddress()
     };
 }
开发者ID:liumeifu,项目名称:OSky,代码行数:11,代码来源:OperatorHelper.cs

示例6: AuthorizeCore

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if(!httpContext.User.Identity.IsAuthenticated)
                return false;

            bool isAuthorized = base.AuthorizeCore(httpContext);

            var userManager = httpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
            bool isConfirmed = userManager.IsEmailConfirmed(httpContext.User.Identity.GetUserId());

            return isAuthorized && isConfirmed;
        }
开发者ID:uaandrei,项目名称:d4232ffg,代码行数:12,代码来源:CustomAuthorizeAttribute.cs

示例7: AuthorizeCore

 protected override bool AuthorizeCore(HttpContextBase httpContext)
 {
     bool authorizeCore = base.AuthorizeCore(httpContext);
     if (authorizeCore)
     {
         // logged in user's email is confirmed?
         string username = httpContext.User.Identity.Name;
         // fetch logged in user detail from database
         ApplicationUserManager userManager = httpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
         ApplicationUser user = userManager.FindByName(username);
         return user.EmailConfirmed;
     }
     return false;
 }
开发者ID:foyzulkarim,项目名称:VirtualTechAcademy,代码行数:14,代码来源:CustomAuthzAttribute.cs

示例8: GetUserPermissions

 /// <summary>
 /// 取当前用户的权限列表
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 private IEnumerable<ApplicationPermission> GetUserPermissions(HttpContextBase context)
 {
     // 取登录名
     var username = context.User.Identity.Name;
     // 构建缓存key
     var key = string.Format("UserPermissions_{0}", username);
     // 从缓存中取权限
     var permissions = HttpContext.Current.Session[key] as IEnumerable<ApplicationPermission>;
     // 若没有,则从db中取并写入缓存
     if (permissions == null)
     {
         // 取roleManager
         var roleManager = context.GetOwinContext().Get<ApplicationRoleManager>();
         // 取用户权限集合
         permissions = roleManager.GetUserPermissions(username);
         // 写入缓存
         context.Session.Add(key, permissions);
     }
     return permissions;
 }
开发者ID:oldkwok,项目名称:Kwop,代码行数:25,代码来源:IdentityAuthorizeAttribute.cs

示例9: AuthorizeCore

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null)
                throw new ArgumentNullException("httpContext");

            var user = httpContext.User;
            if (!user.Identity.IsAuthenticated)
                return false;

            var dbContext = httpContext.GetOwinContext().Get<ApplicationDbContext>();
            var roleAccess = from ra in dbContext.RoleAccesses
                             let userId = dbContext.Users.FirstOrDefault(u => u.UserName == user.Identity.Name).Id
                             let roleIds = dbContext.Roles.Where(r => r.Users.Any(u => u.UserId == userId)).Select(r => r.Id)
                             where roleIds.Contains(ra.RoleId)
                             select ra;

            if (roleAccess.Any(ra =>
                ra.Controller.Equals(_requestControllerName, StringComparison.InvariantCultureIgnoreCase) &&
                ra.Action.Equals(_requestedActionName, StringComparison.InvariantCultureIgnoreCase)))
                return true;

            return false;
        }
开发者ID:huangzulin,项目名称:DynamicRoleBasedAccess,代码行数:23,代码来源:CustomAuthorizeAttribute.cs

示例10: GetAuthenticationManager

		private static IAuthenticationManager GetAuthenticationManager(HttpContextBase context)
		{
			return context.GetOwinContext().Authentication;
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:4,代码来源:AuthenticationManager.cs

示例11: GetPermissionAuthorize

 // Methods
 protected override PermissionAuthorize GetPermissionAuthorize(HttpContextBase httpContext)
 {
     return new ApplicationPermissionAuthorize(httpContext.GetOwinContext().Get<ApplicationPermissionManager>());
 }
开发者ID:bellomoto,项目名称:CLK.AspNet.Identity,代码行数:5,代码来源:RBACAuthorizeAttribute.cs

示例12: LoginUser

 public void LoginUser(HttpContextBase context, User user)
 {
     IAuthenticationManager authManager = context.GetOwinContext().Authentication;
     authManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
     authManager.SignIn(new AuthenticationProperties { IsPersistent = true },
         userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie));
 }
开发者ID:alin-rautoiu,项目名称:Cart42,代码行数:7,代码来源:CustomerService.cs

示例13: GetCurrentUserPilot

        public static Pilot GetCurrentUserPilot(HttpContextBase context)
        {
            // Return Session Cache if set
            if (context.Items["CurrentUserPilot"] != null)
            {
                var ghostUserPilotSession = context.Items["CurrentUserPilot"] as Pilot;
                if (ghostUserPilotSession != null)
                {
                    return ghostUserPilotSession;
                }
            }

            if (!context.Request.IsAuthenticated) return new Pilot();

            var userManager = context.GetOwinContext().GetUserManager<ApplicationUserManager>();
            var user = userManager.FindById(context.User.Identity.GetUserId());
            Pilot ghost = new Pilot();
            if (user != null)
            {
                ghost = user.Pilot ?? new Pilot();
            }

            // Set Session Cache
            context.Items.Remove("CurrentUserPilot");
            context.Items.Add("CurrentUserPilot", ghost);

            // Return Current User Pilot
            return ghost;
        }
开发者ID:janhebnes,项目名称:startlist.club,代码行数:29,代码来源:PilotController.cs


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