ASP. Determine if the current Script is being executed as inclusive

Let's say I have the following pages:

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

%>

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

      

I need this to work so that if I access http://Example.com/Include.asp directly , I see "True", but if I access http://Example.com/Outside.asp I see False. I wouldn't add anything to Outside.asp. Can anyone think of a way to create such IsIncluded function in ASP? I was able to create such a function in PHP by comparing it __FILE__

to $ _SERVER ['PHP_SELF'], but it doesn't work here because ASP doesn't have anything like __FILE__

that that I know of.

+2


source to share


2 answers


Try to check the url and match it to 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")
}

      

+1


source


It is generally not good practice in ASP to have an include file also available as something that can be selected by the client. If you specifically want the client not to download the include file, put your included ones in a folder (called say "Includes"), then block access to that folder in IIS.

OTH if you want the user to be able to access the included file pretty much as it is and also allow other pages to include it, then create a "host" page to include. For example: -.



# /Includes/Include.asp
<%
%>

# IncludeHost.asp
<!-- #include virtual="/Includes/Include.asp" -->

# Outside.asp
<!-- #include virtual="/Includes/Include.asp" -->
<%
   '' #Other content/code here
%>

      

You can now move code and content that was unique to "include.asp" when it was accessed directly in the IncludeHost.asp file.

0


source







All Articles