CODEDIGEST
Home Articles CodeDigest Tutorials FAQs
Skip Navigation LinksHome » Article » IIS Article » VBScript code for setting HttpRedirect Property for a IIsWebFile programmatically   You are not logged in.
Search
 

Technologies
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
VBScript code for setting HttpRedirect Property for a IIsWebFile programmatically

By Rakki Muthukumar
Posted On Feb 20,2008
Article Rating: (Login)
Be first to rate
this article.
No of Comments: 0
Print this article.
Category: IIS

Subscribe to our feed!

VBScript code for setting HttpRedirect Property for a IIsWebFile programmatically

I was helping one of my colleague whose customer wanted a custom VBScript file which sets redirection for certain files under a virtual directory. He wanted to use VBScript alone to achieve this.

A IIsWebFile node will be created in the metabase only when you specifically set a property for the file like HttpRedirect through the IIS manager UI. The below script, gets the IIsWebVirtualDir object of the virtual directory we are interested in, creates a IIsWebFile node and sets it HttpRedirect property:

 

' Virtual Directory under which you need to create the IIsWebFile

vDirName = "IIS://localhost/w3svc/1/root/artinstitutes"

' Getting the Virtual Directory (IIsWebVirDir object)

Set IIsWebVirtualDirObj = GetObject(vDirName)

 

' Call the CreateAWebFile function and pass the IIsWebVirDir object we have with the file name and the redirect url

CreateAWebFile(IIsWebVirtualDirObj, "test.html", "/check.asp?id=0")

CreateAWebFile(IIsWebVirtualDirObj, "test1.html","/check.asp?id=1”)

 

' Commit the changes to the Metabase

IIsWebVirtualDirObj.SetInfo()

 

' This function takes 3 arguments

' 1 = IISObject – the container object

' 2 = filename – physical FileName which needs to be redirected

' 3 = redirectFileName – redirect URL

Function CreateAWebFile(ByVal IISObject, ByVal fileName, ByVal redirectName)

 

    Set myFileCheck = GetObject(vDirname & "/" & fileName)

 

    If (Err.Number <> 0) Then

        Set myFile = IISObject.Create("IIsWebFile", fileName)

        myFile.HttpRedirect = redirectName & " ,PERMANENT"

        myFile.SetInfo()

    Else

        myFileCheck.HttpRedirect = redirectName & " ,PERMANENT"

        myFileCheck.SetInfo()

    End If

 

End Function

Hope this helps!

Similar Articles
  • You can contribute to CodeDigest.Com:
    Article Feedback
    Title  
    Submitted By  
    Comment  
    Enter the verification number
     
    Comments