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


C# UserManager.GetUser方法代码示例

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


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

示例1: OnActionExecuting

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
      if(filterContext == null)
      {
        throw new ArgumentNullException("filterContext");
      }

      var cookies = new CookieManager(filterContext);
      var users = new UserManager(new DataManager(filterContext.HttpContext));

      // only check when we actually have users
      if(users.GetUserCount() > 0)
      {
        User user = users.GetUser(cookies.GetUserToken());

        if(user == null)
        {
          filterContext.Result = new HttpUnauthorizedResult("U heeft geen toegang.");
        }
        else
        {
          if(!string.IsNullOrEmpty(Role))
          {
            var prop = user.GetType().GetProperty(Role);
            if(prop != null && !((bool)prop.GetValue(user)))
            {
              filterContext.Result = new HttpUnauthorizedResult("U heeft geen toegang.");
            }
          }
        }
      }
    }
开发者ID:overeemm,项目名称:dereddingsark.nl,代码行数:32,代码来源:CustomAuthorizeAttribute.cs

示例2: AssignCustomerToRoles

        internal static void AssignCustomerToRoles(UserManager userManager, RoleManager roleManager, CatalogManager catalogManager, Guid userId, Order order)
        {
            using (new ElevatedModeRegion(roleManager))
            {
                bool associationsFound = false;
                foreach (OrderDetail detail in order.Details)
                {
                    var product = catalogManager.GetProduct(detail.ProductId);
                    if (product.AssociateBuyerWithRole != Guid.Empty)
                    {
                        var user = userManager.GetUser(userId);
                        try
                        {
                            var role = roleManager.GetRole(product.AssociateBuyerWithRole);
                            roleManager.AddUserToRole(user, role);
                            associationsFound = true;
                        }
                        catch (ItemNotFoundException)
                        {
                            // skip over the role if it no longer exists
                        }
                    }
                }

                if (associationsFound)
                {
                    roleManager.SaveChanges();
                }
            }
        }
开发者ID:vkoppaka,项目名称:Sitefinity-Custom-Checkout,代码行数:30,代码来源:UserProfileHelper.cs

示例3: OnActionExecuting

    protected override void OnActionExecuting(ActionExecutingContext filterContext)
    {
      Data = new DataManager(filterContext.HttpContext);
      Mailer = new SiteMailer();
      Mailer.EmailLogoPath = filterContext.HttpContext.Server.MapPath("~/email-logo.png");
      Cookies = new CookieManager(this);
      Users = new UserManager(Data);

      base.OnActionExecuting(filterContext);

      if(filterContext.HttpContext.Request.HttpMethod.Equals("GET", StringComparison.InvariantCultureIgnoreCase)
        && !filterContext.HttpContext.Request.IsSecureConnection && Cookies.UseHttps())
      {
        string url = Environment.GetAbsoluteDomain(true) + filterContext.HttpContext.Request.RawUrl;
        filterContext.Result = new RedirectResult(url);
      }
      else
      {
        UserToken token = Cookies.GetUserToken();
        User user = Users.GetUser(token);
        ViewBag.CurrentUser = CurrentUser = user;

        /* Set user context for API calls */
        if(CurrentUser == null)
        {
          var apiToken = new HeaderManager().GetApiToken(Request.Headers);
          ViewBag.CurrentUser = CurrentUser = Users.GetApiUser(apiToken);
        }

        ViewBag.Message = Cookies.GetMessage();
        Cookies.ClearMessage();

        if(CurrentUser == null || !CurrentUser.EnableProfiler)
        {
          MiniProfiler.Stop(true);
        }
        else
        {
          ViewBag.IncludeProfiler = true;
        }
      }
    }
开发者ID:overeemm,项目名称:dereddingsark.nl,代码行数:42,代码来源:BaseController.cs


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