public IUser LoadUser(System.Security.Principal.IPrincipal principal) { var userId = ApplicationEventManager.GetCurrentUserId(principal); if (userId == null) { var cookieValue = CookieProperty.Get <string>(".ASPXAUTH", defaultValue: null); if (cookieValue.HasValue()) { userId = FormsAuthentication.Decrypt(cookieValue).Name; } } if (userId == null) { return(null); // throw new Exception("There is no current user logged in."); } return(Database.Get <IUser>(userId)); }
/// <summary> /// Sends this error as a notification email to the address in web.config as Error.Notification.Receiver. /// </summary> public static async Task <IEmailQueueItem> SendAsNotification(this Exception error, string toNotify) { var context = Context.HttpContextAccessor.HttpContext; if (toNotify.IsEmpty()) { return(null); } var email = EmailService.EmailQueueItemFactory(); email.To = toNotify; email.Subject = "Error In Application"; email.Body = $"URL: {context?.Request?.ToRawUrl()}{Environment.NewLine}" + $"IP: {context?.Connection.RemoteIpAddress}{Environment.NewLine}" + $"User: {ApplicationEventManager.GetCurrentUserId(context?.User)}{Environment.NewLine}" + error.ToLogString(error.Message); await Entity.Database.Save(email); return(email); }
/// <summary> /// Sends this error as a notification email to the address in web.config as Error.Notification.Receiver. /// </summary> public static IEmailQueueItem SendAsNotification(this Exception error, string toNotify) { if (toNotify.IsEmpty()) { return(null); } var email = EmailService.EmailQueueItemFactory(); email.To = toNotify; email.Subject = "Error In Application"; email.Body = "URL: " + HttpContext.Current?.Request?.Url + Environment.NewLine + "IP: " + HttpContext.Current?.Request?.UserHostAddress + Environment.NewLine + "User: " + ApplicationEventManager.GetCurrentUserId(HttpContext.Current?.User) + Environment.NewLine + error.ToLogString(error.Message); Database.Save(email); return(email); }