Click here to Skip to main content
15,894,410 members
Articles / Web Development / ASP.NET

Three Tier Code Generator For ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.78/5 (34 votes)
8 Jul 200512 min read 426.1K   22.2K   251  
Generates three tier code for ASP.NET.
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Diagnostics

Namespace WebChamps.Components.Web
    Public Class SitePage
        Inherits System.Web.UI.Page

        ' Page Events
        '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        Protected Overrides Sub OnInit(ByVal e As EventArgs)

            MyBase.OnInit(e)
            AddHandler Me.Load, AddressOf SitePage_Load
            AddHandler Me.Error, AddressOf SitePage_Error

        End Sub


        Private Sub SitePage_Load(ByVal sender As Object, ByVal e As EventArgs)

            If Context.User.Identity.IsAuthenticated Then

            End If

        End Sub


        Protected Sub SitePage_Error(ByVal sender As Object, ByVal e As EventArgs)

            Dim currentError As Exception = Server.GetLastError()

            ' Write error to log file if not already done by AppException
            If Not (TypeOf currentError Is AppException) Then
                AppException.LogError(currentError.Message.ToString)
            End If

            ' Show error on screen
            ShowError(currentError)

            ' Clear error so that it does not buble up to Application Level
            Server.ClearError()

        End Sub



        ' Shared Methods
        '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        Public Shared Sub ShowError(ByVal currentError As Exception)

            Dim context As HttpContext = HttpContext.Current

            context.Response.Write( _
              "<link rel=""stylesheet"" href=""/Dummy/CSS/Site.css"">" & _
              "<h2>Error</h2><hr/>" & _
              "An unexpected error has occurred on this page." & _
              "The system administrators have been notified.<br/>" & _
              "<br/><b>The error occurred in:</b>" & _
                "<pre>" & context.Request.Url.ToString & "</pre>" & _
              "<br/><b>Error Message:</b>" & _
                "<pre>" & currentError.Message.ToString & "</pre>" & _
              "<br/><b>Error Stack:</b>" & _
               "<pre>" & currentError.ToString & "</pre>")

        End Sub


    End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Australia Australia
Stevan is a Microsoft Certified Solutions Developer in .Net Architecture (MCSD.Net Early Achiever – one among the first 2500 worldwide), Microsoft Certified Application Developer in .Net – MCAD.Net (Charter Member - one among the first 5000 developers worldwide).

Comments and Discussions