Esempio n. 1
0
        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

            // Get the exception object.
            Exception exc = Server.GetLastError();

            // Handle HTTP errors
            if (exc.GetType() == typeof(HttpException))
            {
                // The Complete Error Handling Example generates
                // some errors using URLs with "NoCatch" in them;
                // ignore these here to simulate what would happen
                // if a global.asax handler were not implemented.
                if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
                {
                    return;
                }

                //Redirect HTTP errors to HttpError page
                Server.Transfer("Default.aspx");
            }

            logger.Fatal("Excepcion (Global.asax). Error: " + exc.Message + " " + exc.InnerException);
            Notificaciones.NotifySystemOps(exc);

            // Clear the error from the server
            Server.ClearError();
        }
Esempio n. 2
0
        public void ManualAdministrador(object sender, EventArgs e)
        {
            try
            {
                using (Entities c = new Entities())
                {
                    APP_ARCHIVOS_GENERALES aag = c.APP_ARCHIVOS_GENERALES.Find(1);

                    if (aag != null)
                    {
                        byte[] filedata = aag.MANUAL_ADMIN;
                        string filename = aag.NOMBRE_MANUAL_ADMIN;

                        if (filename == null || filedata == null)
                        {
                            logger.Error(this.GetType().FullName + ". Error 1: no se ha podido encontrar el manual de admin en la BBDD (reg 1 de APP_ARCHIVOS_GENERALES)");
                        }
                        else
                        {
                            string contentType = MimeMapping.GetMimeMapping(filename);
                            var    cd          = new System.Net.Mime.ContentDisposition
                            {
                                FileName = filename,
                                Inline   = false,
                            };

                            Response.AppendHeader("Content-Disposition", cd.ToString());
                            Response.ContentType = MimeMapping.GetMimeMapping(filename);
                            Response.AddHeader("content-length", aag.MANUAL_ADMIN.Length.ToString());
                            Response.BinaryWrite(aag.MANUAL_ADMIN);
                        }
                    }
                    else
                    {
                        logger.Error(this.GetType().FullName + ". Error 2: no se ha podido encontrar el manual de admin en la BBDD (reg 1 de APP_ARCHIVOS_GENERALES)");
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(this.GetType().FullName + ". Error: " + ex.Message + " " + ex.InnerException);
                Notificaciones.NotifySystemOps(ex);
            }
        }
Esempio n. 3
0
        public static void SendEmail(string to, string subject, string body)
        {
            System.Net.Configuration.SmtpSection smtp = new System.Net.Configuration.SmtpSection();
            var section = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;

            //Aunque lo marca como obsoleto, no funciona bien la alternativa (System.Net.Mail.MailMessage), en ese caso da el siguiente error:
            //El servidor ha cometido una infracción de protocolo La respuesta del servidor fue: UGFzc3dvcmQ6
            //Más info: https://tutel.me/c/programming/questions/35148760/c+smtp+authentication+failed+but+credentials+are+correct
            System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
            msg.Body = body;

            string smtpServer       = section.Network.Host;
            string userName         = section.Network.UserName;
            string password         = section.Network.Password;
            int    cdoBasic         = 1;
            int    cdoSendUsingPort = 2;

            if (userName.Length > 0)
            {
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer);
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", section.Network.Port);
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsingPort);
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic);
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
            }
            msg.To              = to;
            msg.From            = section.From;
            msg.Subject         = subject;
            msg.BodyFormat      = MailFormat.Html;//System.Text.Encoding.UTF8;
            SmtpMail.SmtpServer = smtpServer;

            try
            {
                SmtpMail.Send(msg);
            }
            catch (Exception ex)
            {
                Logger logger = NLoggerManager.Instance;
                logger.Error("Error al enviar correo. Error: " + ex.Message + " " + ex.InnerException);
                Notificaciones.NotifySystemOps(ex);
                throw ex;//devolvemos la excepción para controlar que no se ha enviado y que la pagina origen lo tenga en cuenta
            }
        }