public static void LogTrace(Logging Log) { var storeDB = new ContactListContext(); storeDB.Loggings.Add(Log); storeDB.SaveChanges(); }
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e) { if (FormsAuthentication.CookiesSupported == true) { if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) { try { //let us take out the username now string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; string roles = string.Empty; using (DAL.ContactListContext entities = new DAL.ContactListContext()) { User user = entities.Users.SingleOrDefault(u => u.username == username); roles = user.roles; } //let us extract the roles from our own custom cookie //Let us set the Pricipal with our user specific details HttpContext.Current.User = new System.Security.Principal.GenericPrincipal( new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';')); } catch (Exception) { //somehting went wrong } } } }
public static void LogTrace(string message) { var context = System.Web.HttpContext.Current; var logEntity = new ContactList.Models.Logging() { Application = "Contact list " + context.Session.SessionID, LogType = "Trace", Message = message, UserId = string.IsNullOrEmpty(context.User.Identity.Name) ? "" : context.User.Identity.Name, CreatedDate = DateTime.Now, }; var storeDB = new ContactListContext(); storeDB.Loggings.Add(logEntity); storeDB.SaveChanges(); }