Redirecting in a COM Object Using IResponse::Redirect
The IResponse::Redirect COM interface method can be used to redirect requests from COM objects that are called by ASP applications.
Example Code
The following example shows you how to use the Visual Basic programming language to redirect a response to the URL that is contained in the global variable gsURL after validating the URL. Visual Basic COM components are ActiveX DLLs that require references to the Microsoft Active Server Pages Object Library and the COM+ Services Type Library.
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "RedirectClass"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Dim myURL As String
Private Sub class_initialize()
myURL = ""
End Sub
Public Property Get sURL() As String
sURL = myURL
End Property
Public Property Let sURL(ByVal sNewURL As String)
myURL = sNewURL
End Property
Public Function ValidateInput(ByVal sInput As String) As Boolean
Dim reValid As RegExp
Set reValid = New RegExp
reValid.Pattern = "^[\w\.:\?&=/]*$"
reValid.MultiLine = False
reValid.Global = True
ValidateInput = reValid.Test(sInput)
End Function
Public Function RedirectTo() As Boolean
If ValidateInput(myURL) Then
Dim objContext As ObjectContext
Dim objResponse As Response
Set objContext = GetObjectContext()
Set objResponse = objContext("Response")
objResponse.Redirect (myURL)
RedirectTo = True
Else
RedirectTo = False
End If
End Function
The following example shows you how to use Visual Basic Scripting Edition (VBScript) to call the RedirectTo function in the COM+ component from an ASP page.
<%@ Language = "VBScript" %>
<HTML>
<HEAD><TITLE>Test the Redirect Component</TITLE></HEAD>
<BODY>
<%
Dim redirURL
redirURL = "https://www.microsoft.com"
Set objRedir = Server.CreateObject("RedirectComponent.RedirectClass")
objRedir.sURL = redirURL
If (False = objRedir.RedirectTo) Then
Response.Write ("Invalid URL: " & redireURL)
End If
%>
</BODY>
</HTML>