Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Redirecting in a COM Object Using IResponse::Redirect

IIS 6.0

The IResponse::Redirect COM interface method can be used to redirect requests from COM objects that are called by ASP applications.

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.

  MultiUse = -1  'True 
  Persistable = 0  'NotPersistable 
  DataBindingBehavior = 0  'vbNone 
  DataSourceBehavior  = 0  'vbNone 
  MTSTransactionMode  = 0  'NotAnMTSObject 
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 
        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" %> 
<HEAD><TITLE>Test the Redirect Component</TITLE></HEAD> 
  Dim redirURL 
  redirURL = "http://www.microsoft.com" 
  Set objRedir = Server.CreateObject("RedirectComponent.RedirectClass") 
  objRedir.sURL = redirURL  
  If (False = objRedir.RedirectTo) Then 
    Response.Write ("Invalid URL: " & redireURL) 
  End If 

© 2015 Microsoft