ASP.NET: I file di configurazione – Codice sorgente dell’esempio

Sorgenti: config_errore.aspxweb.configerrorpage.aspxglobal.asax

Scarica i sorgenti: aspnet12.zip

Articolo a cui si riferisce il codice: ASP.NET: I file di configurazione

config_errore.aspx

  1 <%@ Page Language="VB" %>
  2 
  3 <!
  4 # nome: Config_errore.aspx #
  5 # scritto da: Antonio Volpon #
  6 # data creazione: 30 Novembre 2001 #
  7 # ultima modifica: 30 Novembre 2001 #
  8 # copyright: Antonio Volpon #
  9 >
 10 
 11 <script runat="server" language="VB">
 12 
 13 Sub Page_Load()
 14 
 15   Dim strSelect As String
 16   Dim objDataSet As New DataSet()
 17   Dim objDataReader As OleDbDataReader
 18   
 19 End Sub
 20 
 21 </script>
 22 

web.config

  1 <?xml version="1.0" encoding="utf-8" ?>
  2 <configuration>
  3  <appSettings>
  4  <add key="ConnectionString" value="Provider=SQLOLEDB.1;data source=antoniov;initial catalog=Biblioteca;uid=anon;pwd=;" />
  5  </appSettings>
  6  <system.web>
  7  <customErrors mode="On" defaultRedirect="errorpage.aspx" />
  8  <sessionState mode="Off" />
  9  </system.web>
 10 </configuration>

errorpage.aspx

  1 <%@ Page Language="VB" %>
  2 
  3 <!
  4 # nome: errorpage.aspx #
  5 # scritto da: Antonio Volpon #
  6 # data creazione: 30 Novembre 2001 #
  7 # ultima modifica: 30 Novembre 2001 #
  8 # copyright: Antonio Volpon #
  9 >
 10 
 11 <script runat="server" language="VB">
 12 </script>
 13 
 14 <html>
 15   <head>
 16     <link rel="stylesheet" href="css/aspnet.css" type="text/css">
 17     </link>
 18     <title>Errore</title>
 19   </head>
 20   <body>
 21   
 22     <div class="titolo">
 23       Errore
 24     </div>
 25     
 26     <hr noshade="true" size="1" width="100%">
 27     
 28     <div class="txtb" id="risposta">Si e’ verificato un errore durante il caricamento della pagina. Ci scusiamo per l’inconveniente</div>
 29     
 30   </body>
 31 </html>
 32 
 33 <html>
 34 <body>

global.asax

  1 <%@ Import Namespace="System.Diagnostics" %>
  2 
  3 <script language="VB" runat="server">
  4 
  5 Sub Application_Error(objSender as Object, objArgs as EventArgs)
  6 
  7   Dim strLogName As String = "Errori Web"
  8   Dim strMessage As String = "Url " & Request.Path & " Errore: " & Server.GetLastError.ToString
  9 
 10   If (Not EventLog.SourceExists(strLogName)) Then
 11     EventLog.CreateEventSource(strLogName, strLogName)
 12   End if
 13 
 14   Dim ELLog as New EventLog
 15   ELLog.Source = strLogName
 16   ELLog.WriteEntry(strMessage, EventLogEntryType.Error)
 17   
 18 End Sub
 19 
 20 </script>