Community Support & Help Center for Hosting, Dedicated Services, Colocation, Design & Development
Hosting, Dedicated Services, Colocation, Design & Development

ASP.Net URL Redirector

Latest post 08-09-2008 7:54 PM by Shawn Hyde. 1 replies.
  • 07-09-2006 2:53 PM

    ASP.Net URL Redirector

    Domain & subdomain url redirection with file/folder security.

    By: Sergeroz

    Language: Visual Basic Script

    Code Snippet:

    This code implements use of the Global.asa file and 1 #include file,
    which should be included in all pages you wish to protect.

    FILES USED: GLOBAL.ASA, DOMAINCHECK.INC, 403.ASP

    Global.asa file detects which domain name your visitors typed in
    (using SERVER_NAME ServerVariable), and sets the DomainNum Session variable
    accordingly.

    DomainCheck.Inc must be included in ALL webpages you wish to "protect" like this:
    <!-- #include virtual="domaincheck.inc" -->
    This file contains code that will check whether visitors are allowed to visit the current URL
    and will deny access or redirect accordingly.

    403.asp is used to report Access Denied for protected URLs. It may be formatted any way
    you wish.

    Sample Scenario 1:
    A visitor navigates to
    www.domain1.com. IIS will first execute Global.asa and will then
    execute index.asp (default page).
    New Session is created: DomainNum = 1, NewSession = True.
    Index.asp contains the #include to domaincheck.inc, so rules are applied before executing
    the remainder of index.asp:
     DenyPath is matched with the '/' entry and ThisURL = HomeURL, thus DoRedirect is called.
     HomeRedirURL is not blank, NewSession = True and ThisURL = HomeURL,
     so the visitor is redirected to '/domain1only/' directory.
    Now, index.asp containing the same #include is found in the /domain1only/ directory and
    domaincheck.inc is executed again:
     DenyPath is not matched (because although '/' entry matches, ThisURL is not HomeURL,
    thus DoRedirect not called.
     AllowOnlyPath is blank so this check is skipped.
     NewSession is set to False.
    Thus, the visitor has now been transparently transferred to the directory containing the
    domain1.com website.

    Sample Scenario 2:
    A visitor navigates to
    www.domain2.com/domain1only/. IIS will first execute Global.asa
    and will then execute index.asp (default page).
    New Session is created: DomainNum = 2, NewSession = True. Index.asp contains the
    #include to domaincheck.inc, so rules are applied before executing the remainder of
    index.asp:
     DenyPath is blank so this check is skipped.
     AllowOnlyPath is not matched so DoRedirect is called.
     HomeRedirURL is not blank, NewSession = True, so the visitor is redirected
     to '/domain2only/' directory.
    Now, index.asp containing the same #include is found in the /domain2only/ directory and
    domaincheck.inc is executed again:
     DenyPath is blank so this check is skipped.
     AllowOnlyPath is matched so DoRedirect is not called.
     NewSession is set to False.
    Thus, the visitor has now been transparently transferred to the directory containing the
    domain2.com website.

    Sample Scenario 3:
    Repeat Sample Scenario 1, then continue:
    The visitor now navigates to
    www.domain1.com/domain2only/ (assuming the Session has not
    yet timed out). Global.asa will not be executed because a current Session is alive
    (DomainNum = 1, NewSession = False). Index.asp in the /domain2only/ directory contains
    the #include to domaincheck.inc, so rules are applied before executing the remainder of
    index.asp:
     DenyPath is matched with the '/domain2only/' entry, thus DoRedirect is called.
     AllowOnlyPath is not blank so this check is skipped.
     HomeRedirURL is not blank, but NewSession = False and ThisURL is not HomeURL, so the
     visitor is redirected to '/403.asp?/domain2only/index.asp'. This page informs the user that
     he is not allowed to access /domain2only/index.asp.

    PASTE THE CODE BELOW INTO YOUR GLOBAL.ASA FILE (CREATE ONE, IF NEEDED)

     

    PASTE THE CODE BELOW INTO YOUR DOMAINCHECK.INC FILE (CREATE ONE, IF NEEDED)

     

  • 08-09-2008 7:54 PM In reply to

    Re: ASP.Net URL Redirector

    ASP.VB Code URL ReWrite without ISAPI, with Subdomain / Domain support

    Replace (text) areas with proper values.

Page 1 of 1 (2 items) | RSS
©1998-2007 · Area51 Computers/Services, all rights reserved.