Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
404 Redirect Questions
Old 01-19-2006, 01:32 PM 404 Redirect Questions
Novice Talker

Posts: 9
Trades: 0
Hello, can anyone tell me what I am supposed to do with this code to make it work?

I already have the web.config and sql setup but I everytime I try creating a file with only that code it displays on ie as text. Thanks for the help!

Code:
Option Strict On
Imports System.Data
Imports System.Configuration
 
Public Class _404Handler
    Inherits System.Web.UI.Page
 
#Region " Web Form Designer Generated Code " 
#End Region
 
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _
                 System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Try
            Dim strQuery As String = Request.ServerVariables("QUERY_STRING")
            If strQuery <> "" Then
                'Now we'll remove the stuff we don't need.
                strQuery = strQuery.Replace("404;http://", "")
                'Get rid of the domain name since we're dealing with multiple domains.
                Dim intSlashPosition As Integer = strQuery.IndexOf("/")
                strQuery = strQuery.Remove(0, intSlashPosition)
                ' now do a lookup in our table to find out if there is a related page.
                Dim NewURL As Integer = DoURLLookup(strQuery)
                If NewURL <> -1 Then
                    Response.Redirect("/DesktopDefault.aspx?TabID=" & NewURL.ToString)
                Else
                    'if we don't have any, just send them to the home page of the site.
                    Response.Redirect("/")
                End If
            Else
                Response.Redirect("/")
            End If
        Catch ex As Exception
            Response.Redirect("/")
        End Try
    End Sub
    
    'This function performs the lookup in the database to find a related page for the broken link.
    Function DoURLLookup(ByVal inURL As String) As Integer
        Dim cnn As New SqlConnection(ConfigurationSettings.AppSettings("connectionString").ToString)
        Dim myCommand As SqlCommand = New SqlCommand("SELECT NewTabID FROM " & _
             "NotFoundLookup WHERE OldURL = '" & Replace(inURL, "'", "''") & "'", cnn)
        cnn.Open()
        Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
        If result.Read Then
            Dim TabID As Integer = CType(result("NewTabID"), Integer)
            cnn.Close()
            Return TabID
        Else
            cnn.Close()
            Return -1
        End If
    End Function
 
End Class
OffTheDeepEnd.c is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-20-2006, 04:59 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
It sounds like your web server isn't set up to handle ASP.NET pages, or that you are using the wrong extention. ASP.NET pages need to have the extention .aspx
Other than that, make sure the .NET framework is installed on the server.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 01-20-2006, 11:43 AM
Novice Talker

Posts: 9
Trades: 0
So if I copy the code and paste it into notepad and call it redirect.aspx, it should work right? I can't get it to do anything but display text.
OffTheDeepEnd.c is offline
Reply With Quote
View Public Profile
 
Old 01-21-2006, 11:46 PM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
It should do if your server is set up correctly. If it doesn't, check that the server has the .NET Framework installed on it
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Reply     « Reply to 404 Redirect Questions
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15976 seconds with 12 queries