private void Log(Exception exception) { //using (StreamWriter writer = new StreamWriter(applicationUrl+filePath, true)) //{ // writer.Write(GenerateCustomMessage(exception)); // writer.WriteLine("Date :" + DateTime.Now.ToString()); // writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); //} try { var log = new Log(); GenerateDBLogRecord(log, exception); using (ProdCustContext context = new ProdCustContext()) { context.Logs.Add(log); context.SaveChanges(); } } catch (Exception errorException) { using (StreamWriter writer = new StreamWriter(filePath, true)) { writer.Write(GenerateCustomMessage(errorException)); writer.Write(Environment.NewLine + Environment.NewLine); writer.Write(GenerateCustomMessage(exception)); writer.WriteLine("Date :" + DateTime.Now.ToString()); writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } } }
protected override bool IsAuthorized(HttpActionContext actionContext) { if (actionContext != null && actionContext.RequestContext != null && actionContext.RequestContext.Principal != null && actionContext.RequestContext.Principal.Identity != null) { var identity = actionContext.RequestContext.Principal.Identity as ClaimsIdentity; if (identity != null) { using (ProdCustContext context = new ProdCustContext()) { var user = context.AppUsers.Where(x => x.UserName.ToLower() == identity.Name.ToLower()).FirstOrDefault(); if (user == null) { return(false); } } } } return(true); }