Ciao a tutti
sto cercando di implementare un gestore di eccezioni non gestite come indicato sia su questo forum e in giro su internet intervenendo sul file global.asax con la gestione della
Sub Application_Error(obj as object,e as eventargs)
End sub
ebbene ho inserito nel global.asax anche la gestione della beginrequest e funziona bene (mi serve per altri motivi) pero' l'error non viene gestito.
Ho creato una pagina con un errore intenzionale , ma senza la direttiva debug="true" mi esce l'errore "eccezione non gestita" ecc ecc , con la debug ="true" esce il listato della pagina che non voglio che si visualizzi.
posto il global.asax per farvi capire, ditemi dove sbaglio o se devo mettere qualcosa nel web.config.
Sub Application_Error(objSender as Object, objArgs as EventArgs)
Dim strLogName As String = "Errori Web"
Dim Message as String
Message = "URL: " & Request.URL.ToString
Message += VbCrLf & "Errore: " & VbCrLf & Server.GetLastError.ToString
Message += VbCrLf & "Referer: " & VbCrLf & Request.UrlReferrer.ToString
Message += VbCrLf & "Browser: " & Request.UserAgent.ToString
Message += VbCrLf & "IP: " & Request.UserHostAddress.ToString
If (Not EventLog.SourceExists(strLogName)) Then
EventLog.CreateEventSource(strLogName, strLogName)
End if
Dim ELLog as New EventLog
ELLog.Source = strLogName
ELLog.WriteEntry(Message, EventLogEntryType.Error)
'spedisco l'errore a me stesso per email
Dim objMessaggio as MailMessage = new MailMessage()
objMessaggio.BodyFormat = MailFormat.html
objMessaggio.To = "mioindirizzo@sito.it"
objMessaggio.From = "mioindirizzo@sito.it"
objMessaggio.Priority = MailPriority.High
objMessaggio.Subject = strLogName
objMessaggio.Body = Message
SmtpMail.SmtpServer = "mail.server.it"
try
SmtpMail.Send(objMessaggio)
catch smtperror as Exception
End Try
Response.Redirect("/path/ErrorPage.htm")
End Sub
Sub Application_BeginRequest(objSender as Object, objArgs as EventArgs)
if Request.Path.IndexOf("\\") >= 0 or System.IO.Path.GetFullPath(Request.PhysicalPath) <> Request.PhysicalPath then
throw new HttpException(404, "not found")
end if
end sub
praticamente vorrei che mi inviasse un'email con i dettagli dell'errore, che venga scritto nel log del server e che l'utente venga indirizzato ad una pagina "innocua".....
tnks per l'aiuto
SuperASP

Rispondi quotando
dovuto ad un copia e incolla selvaggio. grazie lo stesso ciao
