Results 1 to 4 of 4

Thread: custom 404 page

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    custom 404 page

    Is there a way that I can code an aspx for the 404 page to get the string. For instance, if the user puts http://website.com/username, and IIS thinks it doesn't exist, then I will redirect to that aspx page and get the username out of that URL, and do another redirect, is it possible?

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: custom 404 page

    One method ..Add global.asax file in your application. Handle the Application_Error Event


    Code:
     Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
            
            Dim ex As Exception = Server.GetLastError
            Dim exWeb As System.Web.HttpException = TryCast(ex, System.Web.HttpException)
            Dim uri As System.Uri = Request.Url
            'If Error code is File not exits redirect to the parent
            If exWeb.ErrorCode = -2147467259 Then
                'Redirect
                'Get the URL'
                'Either by 
                'uri.LocalPath 
                
            End If
            
        End Sub
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

  4. #4
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: custom 404 page

    If it's IIS doing the "thinking" then .net may not even be handling the request. For example the page/url does not end in .aspx etc then no asp.net code can execute.

    If this is the case there are various ways you could get asp.net to handle the request like
    in IIS set a aspx page to be showen as the default 404 error page and do your thing on that page. Or you could write your own httpHandler or maybe HttpModule if you google them heaps of info will come up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width