Example #1
0
        //Probar con este , es el actual

        public FileResult GetErrorById(string errorId)
        {
            LogErrorDto log = new LogErrorDto();
            var         id  = int.Parse(errorId);

            using (var context = new NuevoDbContext())
            {
                log = context.ErrorLogs.Where(x => x.Id == id).FirstOrDefault();
                string Nombre = "Error" + Convert.ToDateTime(DateTime.Now).ToString("yyyyMMdd") + ".txt";

                string line1 = log.Fecha.ToString();
                string line2 = log.Error.ToString();
                string line3 = log.UrlRequest.ToString();
                string line4 = log.UserId.ToString();
                string line5 = log.ErrorDetallado.ToString();
                string line6 = log.Id.ToString();

                string error_folder = ConfigurationManager.AppSettings["ErrorLogPath"].ToString();
                var    ruta         = error_folder + Nombre;
                var    logFinal     = new StreamWriter(@ruta);
                logFinal.WriteLine(line1);
                logFinal.WriteLine(line2);
                logFinal.WriteLine(line3);
                logFinal.WriteLine(line4);
                logFinal.WriteLine(line5);
                logFinal.WriteLine(line6);
                logFinal.WriteLine();
                logFinal.Close();


                return(File(Nombre, "application/txt", ruta));
            }
        }
Example #2
0
        public List <string> GetUserRoles(string user, string aplication, string system)
        {
            string        error      = "";
            List <string> listResult = new List <string>();

            try
            {
                string     app        = "*";
                string     sys        = system;
                LdapServer ldapServer = new LdapServer(SetDataConfiguration());
                listResult = ldapServer.GetUserRoles(user, app, sys);

                //var itenes = "No trajo ningún DnRol";
                //foreach (var item in listResult) {
                //    itenes = item + " <--> ";
                //}
                //using (NuevoDbContext db = new NuevoDbContext())
                //{
                //    var log = new LogErrorDto();
                //    log.Fecha = DateTime.Now;
                //    log.Error = itenes;
                //    log.UserId = user;
                //    //log.ErrorDetallado = itenes;
                //    db.Add(log);
                //    db.SaveChanges();
                //}
            }
            catch (Exception ex)
            {
                error = ex.Message;
                using (NuevoDbContext db = new NuevoDbContext())
                {
                    var log = new LogErrorDto();
                    log.Fecha = DateTime.Now;
                    log.Error = error;
                    db.Add(log);
                    db.SaveChanges();
                }
            }
            return(listResult);
        }
Example #3
0
        protected void Application_Error()
        {
            Exception   ex   = this.Server.GetLastError();
            var         url  = Request.Url.ToString();
            var         user = HttpContext.Current.User.Identity.Name;
            ErrorLogger log  = new ErrorLogger(ex, url, user);

            using (NuevoDbContext context = new NuevoDbContext()) {
                var e = new LogErrorDto();
                e.Fecha = DateTime.Now;
                e.Error = ex.Message;
                //if (ex.) {
                //    var errorMessages = ex.EntityValidationErrors
                //        .SelectMany(x => x.ValidationErrors)
                //        .Select(x => x.ErrorMessage);
                //}
                e.UrlRequest     = url;
                e.UserId         = user;
                e.ErrorDetallado = ex.ToString();
                context.Add(e);
                context.SaveChanges();
            }
        }
Example #4
0
        public bool LoginUser(string user, string pwd)
        {
            bool   result = false;
            string data   = "";

            try
            {
                LdapServer ldapServer = new LdapServer(SetDataConfiguration());
                result = ldapServer.AuthenticateUser(user, pwd);
            }
            catch (Exception ex)
            {
                data = ex.Message;
                using (NuevoDbContext db = new NuevoDbContext())
                {
                    var log = new LogErrorDto();
                    log.Fecha = DateTime.Now;
                    log.Error = data;
                    db.Add(log);
                    db.SaveChanges();
                }
            }
            return(result);
        }
Example #5
0
        public bool enviaMail()
        {
            if (To.Trim().Equals("") || Message.Trim().Equals("") || Subject.Trim().Equals(""))
            {
                error = "El mail, el asunto y el mensaje son obligatorios";
                return(false);
            }


            //comienza-------------------------------------------------------------------------
            try
            {
                Email = new System.Net.Mail.MailMessage(From, To, Subject, Message);


                if (Archivo != null)
                {
                    foreach (string archivo in Archivo)
                    {
                        if (System.IO.File.Exists(@archivo))
                        {
                            Email.Attachments.Add(new Attachment(@archivo));
                        }
                    }
                }

                Email.IsBodyHtml = true;
                Email.From       = new MailAddress(From);


                //System.Net.Mail.SmtpClient smtpMail = new System.Net.Mail.SmtpClient("smtp.gmail.com");
                System.Net.Mail.SmtpClient smtpMail = new System.Net.Mail.SmtpClient("SMTPAPPL01.telecom.com.ar");
                smtpMail.EnableSsl             = false; //le definimos si es conexión ssl
                smtpMail.UseDefaultCredentials = false; //le decimos que no utilice la credencial por defecto
                                                        //smtpMail.Host = "smtp.gmail.com"; //agregamos el servidor smtp
                                                        //smtpMail.Port = 587; //le asignamos el puerto, en este caso gmail utiliza el 465
                smtpMail.Host = "SMTPAPPL01.telecom.com.ar";
                smtpMail.Port = 25;
                //smtpMail.Credentials = new System.Net.NetworkCredential(DE, PASS);


                smtpMail.Send(Email);


                smtpMail.Dispose();


                return(true);
            }
            catch (Exception ex)
            {
                using (NuevoDbContext db = new NuevoDbContext()) {
                    error = ex.Message;
                    var log = new LogErrorDto();
                    log.Fecha = DateTime.Now;
                    log.Error = error;
                    db.Add(log);
                    db.SaveChanges();
                }

                return(false);
            }
        }