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
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!"