Search code examples
asp-classicincludeserver-side-includes

ASP - Determine if current Script is being run as an include


Lets say I have the following pages:

# Include.asp
<%
Response.Write IsIncluded() & "<br>"

%>

# Outside.asp
<!--#include file="Include.asp" --> 

I need this to work such that if I access http://Example.com/Include.asp directly, I see "True", yet if I access http://Example.com/Outside.asp I see False. I'd perfer not to have to add anything to Outside.asp. Can anyone think of a way to create such an IsIncluded function in ASP? I was able to create such a function in PHP by comparing __FILE__ to $_SERVER['PHP_SELF'], but that won't work here becasue ASP doesn't have anything like __FILE__ that I am aware of.


Solution

  • Try checking the URL requested and match it against the include. Example provided in JavaScript

    function IsIncluded() {
      var url = String(Request.ServerVariables("URL"));
      url = url.substring(0, url.indexOf("?")).substring(0, url.indexOf("#")).substr(url.lastIndexOf("/"));
      return (url == "Include.asp")
    }