本文整理汇总了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.");
}
}
}
}
}
示例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();
}
}
}
示例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;
}
}
}