Elmah.ErrorMailModule.OnInit C# (CSharp) Méthode

OnInit() protected méthode

Initializes the module and prepares it to handle requests.
protected OnInit ( System.Web.HttpApplication application ) : void
application System.Web.HttpApplication
Résultat void
        protected override void OnInit(HttpApplication application)
        {
            if (application == null)
                throw new ArgumentNullException("application");
            
            //
            // Get the configuration section of this module.
            // If it's not there then there is nothing to initialize or do.
            // In this case, the module is as good as mute.
            //

            var config = (IDictionary) GetConfig();

            if (config == null)
                return;

            //
            // Extract the settings.
            //

            var mailRecipient = GetSetting(config, "to");
            var mailSender = GetSetting(config, "from", mailRecipient);
            var mailCopyRecipient = GetSetting(config, "cc", string.Empty);
            var mailSubjectFormat = GetSetting(config, "subject", string.Empty);
            var mailPriority = (MailPriority) Enum.Parse(typeof(MailPriority), GetSetting(config, "priority", MailPriority.Normal.ToString()), true);
            var reportAsynchronously = Convert.ToBoolean(GetSetting(config, "async", bool.TrueString));
            var smtpServer = GetSetting(config, "smtpServer", string.Empty);
            var smtpPort = Convert.ToUInt16(GetSetting(config, "smtpPort", "0"), CultureInfo.InvariantCulture);
            var authUserName = GetSetting(config, "userName", string.Empty);
            var authPassword = GetSetting(config, "password", string.Empty);
            var sendYsod = Convert.ToBoolean(GetSetting(config, "noYsod", bool.FalseString));
            var useSsl = Convert.ToBoolean(GetSetting(config, "useSsl", bool.FalseString));
            //
            // Hook into the Error event of the application.
            //

            application.Error += OnError;
            ErrorSignal.Get(application).Raised += OnErrorSignaled;
            
            //
            // Finally, commit the state of the module if we got this far.
            // Anything beyond this point should not cause an exception.
            //

            _mailRecipient = mailRecipient;
            _mailSender = mailSender;
            _mailCopyRecipient = mailCopyRecipient;
            _mailSubjectFormat = mailSubjectFormat;
            _mailPriority = mailPriority;
            _reportAsynchronously = reportAsynchronously;
            _smtpServer = smtpServer;
            _smtpPort = smtpPort;
            _authUserName = authUserName;
            _authPassword = authPassword;
            _noYsod = sendYsod;
            _useSsl = useSsl;
        }