Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    85

    Log degli errori e relativa gestione

    Salve a tutti,
    vi scrivo per chiedervi un consiglio.
    Sto realizzando un sito e mi piacerebbe loggare gli errori delle varie pagine (qualora ne avvengano) in modo poi da poter consultare questi log ed accorgermi di eventuali malfunzionamenti.

    Come potrei fare?
    Pensavo a due possibili soluzioni:
    1- mettere try -catch in ogni pagina ed ogni metodo, e richiamando il metodo che logga all'interno del catch. Certo però che dovrei veramente metterlo dapertutto...

    2- utilizzare la pagina di errore. E' possibile nella pagina aspx dell'errore risalire alla pagina mandante ed addirittura anche risalire al testo dell'eccezione?
    Potrei in caso distinguere il tipo di errore (nel senso che se arrivo alla pagina di errore per pagina non esistente, evito di fare il log) ?

    Cosa mi consigliate?

    Ciao, grazie!

  2. #2
    Sicuramente un gestore globale di errori usando le caratteristiche di ASP.NET, quindi l' handle degli errori nel global.asax.
    Questo metodo intercetta gli errori:
    codice:
    protected void Application_Error(object sender, EventArgs e)
    {
    	Exception excpt = Server.GetLastError().GetBaseException();
    }
    Adesso puoi decidere che fare con questa eccezione, ad esempio, loggarla e poi reindirizzare l' utente altrove ...

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    85
    Ciao, sinceramente non conoscevo global.asax , nè a cosa potesse servire.
    Me lo studio su e lo tengo in considerazione come un'ottima soluzione.
    Si, sicuramente occorre farre una gestione globale per non replicare mille volte il codice.

    Una cosa: con la soluzione che mi proponi, si riuscirebbe anche ad intercettare l'errore di pagina non trovata?

    Ciao, grazie!

  4. #4
    Certo, con il global.asax intercetti tutto quel che succede nella tua applicazione ASP.NET.
    Questo articolo potrebbe servirti (in inglese):


    Methods corresponding to events that fire on each request
    Application_BeginRequest() – fired when a request for the web application comes in.
    Application_AuthenticateRequest –fired just before the user credentials are authenticated. You can specify your own authentication logic over here.
    Application_AuthorizeRequest() – fired on successful authentication of user’s credentials. You can use this method to give authorization rights to user.
    Application_ResolveRequestCache() – fired on successful completion of an authorization request.
    Application_AcquireRequestState() – fired just before the session state is retrieved for the current request.
    Application_PreRequestHandlerExecute() - fired before the page framework begins before executing an event handler to handle the request.
    Application_PostRequestHandlerExecute() – fired after HTTP handler has executed the request.
    Application_ReleaseRequestState() – fired before current state data kept in the session collection is serialized.
    Application_UpdateRequestCache() – fired before information is added to output cache of the page.
    Application_EndRequest() – fired at the end of each request
    Methods corresponding to events that do not fire on each request
    Application_Start() – fired when the first resource is requested from the web server and the web application starts.
    Session_Start() – fired when session starts on each new user requesting a page.
    Application_Error() – fired when an error occurs.
    Session_End() – fired when the session of a user ends.
    Application_End() – fired when the web application ends.
    Application_Disposed() - fired when the web application is destroyed.

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    85
    Perfetto, grazie mille! Anche per la pronta risposta, velocissimo!
    Mi sei stato di grande aiuto!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.