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.
Related
I have no idea about asp, but I had to do some modifications in a web site, an easy modification. So I downloaded all files from server and I did all the modifications in Visual Studio 2013. Then I tested each page in the local host and it was perfect.
When I uploaded the files, I created a folder called "development", to tested it before I changed in the real site, so, my real site is for example "www.realsite.com" and my new folder is inside, with all the file, so I write in my url "www.realsite.com/development" and it shows the page, but not the one I had modified, but the real site. I want to know if there is a config file to change the path of the development site to see the changes I make and not the real site, because if I click in the development site a menu, it sends me to the page in the real site.
I hope you can help me with this,
Thank you!
PS: Do you know what is the meaning of "~/" in for example : src="~/folder/folder/xxxx.xx"
This is because the URLs in the project are using absolute paths, all pointing to the root. If they were using relative paths, moving the project to a folder and running it from there would work just file.
The difference:
... <-- absolute, note the leading slash
... <-- relative, no leading slash
Well, it depends on what kind of changes you are referring to, what kind of ASP.net site (or application).
The ~/ in ASP.Net means "path from application root". A subfolder (the new folder you created) in an existing application is just that, a folder. It is not "another application root". So if the existing code refers to "its root", e.g. where it uses ~/, it's probably not what you would expect..
Again, not enough info, but if you experience more unexpected behavior, it will probably be because of this (application scope).
Ref: ASP.NET Web Project Paths
ASP.NET includes the Web application root operator (~), which you can use when specifying a path in server controls. ASP.NET resolves the ~ operator to the root of the current application.
Hth...
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
I am a Systems Administrator (not for a company just work for a 3rd party company), and having an issue with an error that i receive on the server side when browsing his website from the server.
Error
Active Server Pages error 'ASP 0126'
Include file not found
/login.asp, line 3
The include file '/includes/connect.asp' was not found
I enabled parent paths in IIS 7 but it stills errors out. I am not a ASP guy at all, but all things in IIS looks ok. Is it his code? Anything he could try? Had a feeling doing research that it has something to do with his paths to his file?
Thanks guys
You may receive an "ASP 0126" error message when you try to view an ASP Web page that is hosted in IIS 6
Please check this post from MSDN. Resolutions are there.
ASP 0126
Just to bring the answer to Stack Overflow. Below are the workarounds.
Method 1: Use the #include virtual statement together with an absolute file path
To work around this issue, use the #include virtual statement together with an absolute file path in the Test.asp Web page. Consider the following code examples:
The following line of code does not work.
<!-- #include virtual ="../Date.asp" -->
The follow line of code works.
<!-- #include virtual ="Samples/Includes/Date.asp" -->
Method 2: Use the #include file statement together with a relative file path
To work around this issue, use the #include file statement together with a relative file path in the Test.asp Web page. Consider the following code samples:
The following line of code does not work.
<!-- #include virtual ="../Date.asp" -->
The following line of code does work.
<!-- #include file ="..\Date.asp -->
Note By default, parent paths are disabled in IIS 6. To enable parent paths, you must manually set the AspEnableParentPaths property in the metabase to TRUE.
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.
I am using code that will get the root path
return HttpContext.Current.Server.MapPath(#"\Schedules\");
This works great when my site is installed as a fully fledged web app. but when its installed as a virtual directory it breaks, because it is looking for files in root folder, and not in \virtualdirectorypath folder.
Is there a way I can change the code to look for files from the virtual directory root, but also so it won't break if the app is installed as a fully fledged website?
Try this:
return HttpContext.Current.Server.MapPath(#"~/Schedule/");
Use ~ root operator.
Server.MapPath("~"); // path of root of web application.
See my answer on Base URL in ASP.net Master Pages with virtual Directories