Why isn't #include working on .asp page in IIS7.5? - asp-classic

I saw a similar question to this, but mine is slightly different:
I'm get intermittent results with #include files working on an IIS 7.5 server (R2008 V2). My includes are only working if they are in the same folder as the current .asp page, or in a subfolder of the current page. This is inconvenient, as I'd like to keep them all in a /lib subfolder, off of the main page.
My configuration: I have a folder named DCN, sitting right below the wwwroot folder. There are several files in a /lib folder within the DCN folder, so the absolute path is c:\inetpub\wwwroot\dcn\lib\my_include_file.asp. If I open an ASP page in the DCN folder, I can pull include files from the /lib subfolder. However, if I open an ASP page from the DCN/trouble folder (such as "DCN\Trouble\Search.asp"), and the search.asp page has a line that says:
<!--#include file="../lib/my_include_file.asp"-->
the include fails, and I get a 500 error.
I've also tried:
<!--#include file="/lib/my_include_file.asp"-->
with the same results. Same with:
<!--#include file="/DCN/lib/my_include_file.asp"-->
I changed the slashes to backslashes, with the same results. I even went so far as to try:
<!--#include file="c:\inetpub\wwwroot\dcn\lib\my_include_file.asp"-->
(out of sheer desparation), but am still getting the same results.
If I create a subfolder in the dcn\trouble folder, I can include files from it, but obviously, this is not ideal.
Any suggestions would be greatly appreciated. I can't help but think this is something trivial. Thanks in advance!

Yots is correct, it sounds like parent paths are turned off. If you can't get these turned on the use virtual paths instead:
Based on your question where you state that the include files are in /DCN/lib then do the following:
<!-- #include virtual="/DCN/lib/my_include_file.asp -->
When using virtual paths you must specify the full virtual path to the file i.e. from the root of the site. This isn't ideal if you're building your application in a subfolder on your development machine where you're using XP and then deploying into the root of a production machine. That said IIS7 on Vista or Windows 7 permits the creation of multiple sites now **.
When using a path type of File="...", filename must be on a relative path to the folder containing the #include. For example:
The directive <!-- #include file="my_include.asp" --> will include my_include.asp from the same folder.
The directive <!-- #include file="lib/my_include.asp" --> will include my_include.asp from the folder lib below the current folder where the script is running.
The directive <!-- #include file="../my_include.asp" --> will include my_include.asp from the folder lib above the current folder (the parent folder) where the script is running.
The directive <!-- #include file="../lib/my_include.asp" --> will include my_include.asp from the folder lib that is a child of the parent folder (or the current folder's sibling).
The last two examples won't work if parent paths are not enabled.
** I am aware there are hacks to enable multiple IIS sites in XP's IIS5.1.

I think your problem is that parent paths are disabled by default in IIS.
You have two options:
Using Virtual Paths
Enabling ASP Parent Paths on IIS
For details read this article from the IIS Website
http://learn.iis.net/page.aspx/566/classic-asp-parent-paths-are-disabled-by-default/

What about a #include virtual? if it reads:
#include virtual="\mysite\include\file.inc
it should find the file.inc in the include folder under mysite? I have enabled and disabled parent paths and tried about a million things. I still receive an asp 0126 error for the file not found. I can swtich it to include file and then it finds it, but then the file.inc has a bunch of other includes and it then cant find them no matter how i change it to include file or virtual. It works in IIS 6, but not IIS 7 that i am moving this site to. It is a classic asp page with mostly everything done in include files
I have mysite in the Default Web site\dept_Sites\mysite location.

Related

ASP classic - alternatives to enabling parent paths when installation directory unknown

I'm continuing development on an ASP Classic web application. It makes heavy use of virtual directories to serve the core application to multiple users on different websites.
In order that these users have a choice of where to install the application (root or otherwise) parent paths are enabled so that relative server side includes can be used without using the root notation and virtual includes. So if I am in the administrator virtual folder and need access to a functions file or something I use the following to traverse up the tree one step then back down into the virtual folder that contains the file I need;
<!--#include file="../one-of-the-virtual-folders/file-i-need.asp" -->
I cant use;
<!--#include virtual="/one-of-the-virtual-folders/file-i-need.asp" -->
as the virtual folder maybe running in a sub directory and actually be
<!--#include virtual="/subdirectory/one-of-the-virtual-folders/file-i-need.asp" -->
I know this at runtime as where the application is being run from is a global variable BUT includes are run before any executed code so Ive no way of letting the include statement know where the application is being run and so what the directory structure is.
Do any brighter people than me out there have any idea how I can avoid the use of parent paths..?
Rolf

using Classic ASP INCLUDE VIRTUAL in ASP.NET page

I maintain an Classic ASP intranet site. I've developed a new page in ASP.NET that has a link to it from the old site. I would like to use the INCLUDE from the intranet which puts a header with menus on each page. I get a compile error when I run the new page in the debugger. The INCLUDE file contains nested INCLUDE files. The error says it can't find the nested includes. It's looking for them in the C:\xxxxxx when the actual physical path is on the d:\ drive.
Apparently it's resolving the INCLUDE VIRTUAL for the top level include, because it's looking for the nested includes.
Why does it resolve the first include, finding it on the D:\ drive, but is looking for the nested includes on the C:\ drive?
here's the code for the top level include
< !--#include virtual="/includes/page2header.asp"-->
here's the code for the nested includes
< !-- #INCLUDE virtual="/inc/menustyles.txt" -->
< !-- #INCLUDE virtual="/inc/Config.asp" -->
The site is running on IIS 7.5.
The site is located on the server on the default website in a virtual directory in the path
D:\inetpub\wwwroot
The compiler is looking for the nested includes in this path with this error,
Could not find a part of the path 'C:\inetpub\wwwroot\inc\menustyles.txt'
Include files don't work in the same way in ASP.NET as they do in classic ASP. When you use the Include directive, it results in the file content being rendered as plain text in the ASP.NET page. You will have to take an ASP.NET route to solve your problem. Typically, User Controls are used to render snippets of reusable HTML.
See my article on this topic for more information: http://www.mikesdotnetting.com/Article/144/Classic-ASP-Include-Files-in-ASP.NET
The problem I was having here is I was running the debugger on my development machine, and it's virtual directory IS on the C:\ drive for this site, and the first level virtual file did exist in the path where the compiler was looking for it, and the nested files did not exist. The problem was solved when I copied the nested files into place on the development machine.
However, that raised a new problem. The nested files contain server side script, Classic ASP VBScript, and it just won't run in my ASP.NET page. This problem brings this effort to a dead end, unless someone can recommend how to solve this new problem.
Thanks, Bren

Virtual include not working

I have recently taken over a website written in Classic ASP which i had no previous experience with.
In the root of the site the default.asp has an include:
#include virtual="/inc/common.asp"
However when hosted on the web server or locally (IIS) it returns with an error which says the include file 'common.asp' could not be found. The inc folder exists in the same directory as the default.asp and the common.asp is in the inc folder.
Any help would be appreciated!
You say that the inc folder is in the same folder as default.asp - however you don't say if this folder is root. #include virtual takes a path from root, so ensure that you have the full path in there.
There's a quick explanation of #include syntax here: http://www.w3schools.com/asp/asp_incfiles.asp
You cannot start an include link in Classic ASP with a slash (/). So your include needs to be like:
#include file="inc/common.asp"
or
#include file="../inc/common.asp"
or
include file="../../inc/common.asp"
Notice that I used "file" instead of "virtual"?
<!--#include file="inc/common.asp" -->
Also, unless your include is within the same folder, you will need to enable "parent paths" in IIS admin.

How might i setup my ASP.NET project to find my files?

edit I do not want to redirect pages, specific files etc. I would like to change the path where images, videos and other media are stored from the root source directory to the directory of my choosing. In this case c:/dev/prjfiles/prjname/public (c:/dev/prjfiles/prjname/ is my working directory) and i except when my html does img src="/pic.png" it will find the image in c:/dev/prjfiles/prjname/publi/pic.png. I need a working solution, i tried looking at how to set virtual directories and etc. I cant figure it out. Thus the bounty. I am generating the html, i am not writing asp:image runat="server" etc i am pulling data from a DB and outputing the html. The part that is still a WIP is the code that handles POST request. The html already exist but i cant have hundreds of files in site.com/here pollution my source directory (c:/dev/trunk/thisprj/thisprj/where my .aspx files are and i do not wish 500 .png/gif/jpg here)
I dont know how asp.net environments are usually set up. I am assuming i have a root path that is not available from the web, a bin/ where i may put my asp.net dll and a public where i stick in any files i want.
I would like to have my project files seperated from everything else. My JS, css and image files are in prjfiles/prjname/public with my sqlite db in prjfiles/prjname/ and extra binaries in prjfiles/prjname/bin.
The problem comes when i run my app and try to load an image. Such as /cssimg/error.png. My project does not find resource in my /public folder and i have no idea how to make it find them. How can i set my project up so it does?
NOTE: I set the working directory path so its at prjfiles/prjname/. In code i write ./bin/extrabin.exe and db.sqlite3 which access the files properly.
You might want to watch the getting started videos for ASP.NET
http://www.asp.net/get-started/
EDIT: More info added
As #Murph suggests, your assumptions are incorrect.
IIS takes care of blocking HTTP access to any important files and folders like your *.aspx.cs, and *.cs in the App_Code, any DLLs, anything under the App_Data directory and the web.config.
Content files, such as *.html, *.css, *.js, .gif, .jpg, .png are all served in the normal manner.
In this way, there is no need for a "public" folder.
I dont know how asp.net environments are usually set up. I am assuming i have a root path that is not available from the web, a bin/ where i may put my asp.net dll and a public where i stick in any files i want.
This is wrong assumption!
You have a root folder, which IS available in public. You set IIS or ASP.NEt Development Server to this folder.
(optional, but always needed) You have a web.config file in this root folder for configuration
You have a bin folder for your assemblies (each page or user control "include" compiles to a class)
(optional) You have App_Data as default folder for file-based DBs and/or other data files (say XML storage, ..)
(optional) You have an App_theme folder for styling and images. Read about ASP.NET themes.
(optional) You can add App_Code folder if you want to add classes to be compiled by the server.
You can create folders for scripts, etc...
Normally for complex logic, etc.. you create in a separate project outside the root and reference the result assembly in the bin folder.
Seriously, you cannot do ASP.NET work without an IDE or a manual. Visual Web Developer 2008 Express IDE is free and http://asp.net has tons of resources for getting started.
I don't know if I got the question right, but maybe you could try the <BASE> HTML tag.
HTML <base> Tag
"Specify a default URL and a default target for all links on a page"
There's a nice and simple example at W3Schools, check it out.
The negative side is that you need to put a <BASE> tag in each page you want.
It sounds like you should be able to create a virtual directory to do what you're asking -- but it's a very non-standard setup.
Keep in mind that IIS will prevent users from downloading DLLs and other project-level files, so you usually don't need to partition them off in a separate layer.
For example, just have a cssimg folder at the top level of your project, and skip the whole public folder thing.
I see where you're coming from. ASP.NET projects are set up a little differently from how you're treating them, but you can make them work like you want.
The root of an ASP.NET project IS publicly accessible. When you created your WebSite within Visual Studio, it created a default.aspx page right on the root. Are you hosting in IIS? If so, it's set up to serve up default.aspx by default. But I digress.
Here's how to make it work like you want (mostly):
Create a WebSite, then right-click the site and add a folder named "prjfiles". Right-click that folder and make another named "public". Create another subfolder of that one called "cssimg".
Now, if you want to use the image you mentioned, you'd reference it like this: "~/prjfiles/public/cssimg/error.png" (pathing starting with the root) or "./cssimg/error.png" if you're coming from a page in the public folder (relative pathing).
Really, though, you're doing too much work. Here's how to make it work with less effort:
Create your WebSite, right-click the project and add a folder called "cssimg".
Treat the root as you would the "public" folder- put your pages right there on the root or in subfolders, as needed. You can reference that same image file like this now: "./cssimg/error.png" (relative) or "~/cssimg/error.png" (start from root)
There's also another way to tell the engine where to look for resources, but it's for your css files. Inside the "head" tag, you can add a "style" element (with type="text/css") and inside that you can add something like this: #import '<%= ResolveUrl("~/prjfiles/public/cssimg/styles.css") %>';
Good luck!
If I correctly understood your problem, you're trying to find files which aren't physically stored on a filesystem folder, or stay on a different folder. You can deal with this problems by implementing a UrlRewrite mechanism.
I suggest you to read URL Rewriting in ASP.NET and, after, to take a look into this implementation: A Complete URL Rewriting Solution for ASP.NET 2.0.
If I understand all this correctly (please comment with any correction) right now all your files are together in the root directory and you use <img src="/img.png" /> and it works.
If this is the case, make another directory in the directory the images are in, say call that directory images and put the image files there. now use <img src="/images/img.png" />.
Done.

adding .net code to a classic asp website, can't reference namespaces in .dll file

I have an existing fairly large classic asp website, with virtual directories configured to centralize certain resources. My problem is for some reason I can't access any of my namespaces and classes. I tried adding a reference to another project where I have classes in a namespace "DAL" and even though intellisense sees the classes and the website compiles fine, it errors when I try to access any page that references a class in the "DAL" namespace.
I get the following error message in my browser "CS0103: The name 'CMS' does not exist in the current context". Part of the problem is website project's root is not the same folder/level as the web root in IIS. So my libraries are in the website root "/bin" folder, but iis is looking for these files in the IIS webroot which is at a lower level. So how can I get .net to see my binaries without putting them in the lower IIS website root directory? I tried setting up a virtual directory to my .dll file but it seems to have no effect.
thank you for your help!
======================CLARIFICATION====================
What I'm trying to do is keep the .dll files I want my website to use in a higher level directory then the folder I have set as the web root in IIS. So say the library i want to use it "DAL" it in the projects /bin folder, but under IIS the default site's Local Path is set to "/site/default". The only way I can seem to use the "DAL" library is by putting the /bin folder into "/site/default/bin", which for this project is not an option. Does this help?
Using an NTFS Junction Point to achieve what sounds like the same goal has been working for me.
By way of an example, I have a web site with 20+ child IIS Applications that are largely identical (don't ask!), rather than duplicating the 'bin' folder in each of these (they would be identical) each child application has a 'bin' junction that points to the 'bin' folder in the web site root.
/bin <- this is the actual 'bin' folder
/app1
/app1/bin <- this is a junction point
/app2
/app2/bin <- this is a junction point
/app3
/app3/bin <- this is a junction point
/images
...
...
To create these junction points, if you're using Vista/Win2k8 or later you can use the built-in command 'mklink', for earlier versions of Windows use the SysInternals junction.exe tool - available here.
Maybe make the website route folder a nested application in IIS?

Resources