Here is what I will do:
In global.asax.cs
protected void Application_PostAuthorizeRequest()
{
if (HttpContext.Current.User != null && HttpContext.Current.User.Identity != null && !string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
{
HttpContext.Current.Items["User"] = userRepo.FetchByUsername(HttpContext.Current.User.Identity.Name);
}
}
public static CustomUser CurrentUser
{
get
{
return HttpContext.Current.Items["User"] as CustomUser;
}
}
then you have a convenient static code with the current user. This is a dirty but effective way to do this.
Of course, indeed, I would add the user to my IOC container and inject it into my controllers using the ControllerFactory controller with IOC support. This is the right thing.
, ! , , , "" , .