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

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

Related

Select correct path for files from App Under IIS

I have inherited an .NET app that is hosted on IIS. Previously it would have been its own site within IIS. Now in my Dev environment I have to run it under Default WebSite (in Production it will still run as its own site.
So in Dev I was having problems loading scripts and css files - so I right click Default Web Site in Dev and Add Application - call the new App - MyApp and point to the physical location on disk.
So previously style sheets would have been loaded:
href="/css/folder/mystylesheet.css"
and js files:
src="/jslib/jquery-1.9.1.js"
which worked fine when the application is hosted as its own site within IIS and which still needs to happen in Production (just not in my dev) So in dev I need to change the css and js as below:
href="~/css/folder/mystylesheet.css" (note ~ added)
src="./jslib/jquery-1.9.1.js" (note . added)
and now the js and css files for MyApp under Default website are loaded. However is there something simple I can do in IIS or webconfig to switch this behaviour on/off easily in Dev/Production rather than editing all the places where scripts and css files are loaded - as I know at some point a file will get checked into Production with the path incorrect
The other problem is there is numerous links throughout the site that are all relative so were /Link/Page.aspx which now break in MyApp hosted under Default Website
EDIT
Looking at the answer below from this question
In ASP.NET, many times you will need to use a tilde (~) to get the application's root directory, so your paths would look like ~/stylesheets/main.css
When you specify a path that starts with / you are indicating the server root so if you have you site in a virtual directory, it will not be taken into account, but if the site is hosted as the default site, the path will qualify:
Example: server named foo.net with site hosted in a virtual directory named app /stylesheet will translate to foo.net/stylesheet not foo.net/app/stylesheet
All my paths start with / (i.e going to server root) - what I need to figure out is there something I could add to web.config that for Dev would let me specify The Virtual Application MyApp needs to be taken into account (just for Dev - this could then be removed in Web Transform for Production web.config file
The short answer is no, there is not one single place where you can deal with the site's location. That's because there are many possible outcomes that you might want, including:
site served from IIS root folder and accessed at root of domain (or not)
site served from IIS subfolder and accessed at same path (or not)
IIS rewrite rules (inbound and outbound), which adds layers of mapping between public and private paths
sites mapping to subdomains, DNS wildcard mapping (where requests are distinguished by hostname), etc
sites mapping to child applications, inheriting or not inheriting rewrite rules (and other configuration)
all of the above
At the same time, there are many places where you interface with paths:
internal physical paths, usually for disk access, and usually requiring mapping of virtual path
internal virtual paths
internal ASP.NET paths, like virtual paths except that they can be app-relative (using ~), which IIS doesn't always recognize
public-facing paths
all of the above can be relative or absolute
So yeah, it's a mess.
For your case, the simplest thing is probably to make the development environment mirror the production environment. Unless you're moving the live site, delegating all the path references to a configuration-aware function is probably more trouble than it's worth.
The ~ is added to make the path relative to root directory. One suggestion is to move the folder up a few levels.or down a few levels to make sure your project is in the correct directory. Hope this works

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

Interacting With Folders Outside The Root/Web Directory With Dreamweaver (CS5)

Using FileZilla, I can access folders that are outside my web directory. How can I do the same with Dreamweaver so that I can edit the files and automatically save/upload all through Dreamweaver? I currently can only access the web directory.
I know how to include them with PHP, but I would like Dreamweaver to find/access them.
Thank you!
You would have to set the Site Definition (both local and remote) paths to look one level higher than you currently have it. So if the local path is
My Documents/Web Sites/This Site
you would change it to
My Documents/Web Sites/
and if the remote is:
/user/home/domain.com/
change to
/user/home/
The problem you are going to run into is that Dreamweaver doesn't work well when set like this. It assumes the Remote path is the public web root and will create all sorts of files and folders there automatically and DW expects those to be in the public root. Also, things like setting paths to includes and images automatically will start to not work as all paths will start outside of the public web root.
Best to leave it as it is and use an external FTP program to handle the files outside of the web site.
We've bumped up against this situation previously where the desire was to have the PHP include files be moved outside the public HTML directory. JCL1178's answer is absolutely conceptually correct.
The actual implementation was to duplicate the site (under "Manage Sites") and essentially create a separate site for the "includes" directory that would go one level up. So the "Root Directory" setting was normal (in our case "public_html/" in the main site and we removed "public_html/" from the Root Directory setting in the "includes" site, effectively causing the path to go one level up.
Definitely not an ideal situation/workflow, to say the least, as you'll end up with two site definitions for one site (which can cause other issues); but Dreamweaver is what it is. We were working on a project offsite that did not allow for anything other than Dreamweaver to be used, so this is what we came up with to comply.
As an added note: we were only able to implement this solution because the webhosting plan allowed us to get to the root. If you're on a webhosting plan that is strictly limited to the public directory, the whole thing will be DOA.

ASP.NET: external custom config file in a virtual directory - how to?

I know that there at least two approaches to leverage the web.config file:
using the configSource attribute which was introduced in .NET 2.0 - here is a good blog entry about it.
The file attribute of the appSettings tag which lets you point to an external file with a relative path. Described in the MSDN documentation on the appSettings element.
Now, my problem is that both approaches work well only for physical paths. But I need to address a config file which is in a virtual directory.
Which other method could I use to put my config resources in a virtual directory?
Note: I want to do it this way, because I have multiple instances of my web application on the same server (and that on many servers). To keep deployment easy and clean, I want to keep one directory for all the files (aspx, ascx, images, css, js etc.) and point the web apps in IIS for different customers (=domains, https etc.) to this single directory. In every IIS web I would have a virtual directory called "custom" which points to a different folder for each web.
Update: I'd like to point out that this virtual directory "custom" is not suited to contain an inherited web.config - that web.config would be valid only for the custom folder which doesn't contain aspx/ascx files.
I have the same scenario and after reading you post I realised that asp.net won't let you do this for various security reasons.
Therefore I turned to the OS to find an equivalent to the Linux soft link function which in turn led me to the Junction utility from sysinternals. This can create a directory that is actually any other directory on that volume and asp.net can't tell the difference and so happy loads the config sections that are not actually in a subdirectory of you website. Works for me :)
Virtual Directories can be set as applications, and you can just place another web.config there.
It will inherit any changes from the parent config, and you can add custom settings in it.
I was looking to do the same thing but it did not work, so I decided to do the opposite, as you know the web.config can be inherited, so I pointed IIS to a folder containing the client config (connection string, file path etc) files and the website files i put them on a virtual directory with the rest of the webconfig (where it load dll and other application files needed)
So basically i can use the website files to multple clients and the clients with their own Database connection string and other specific client settings.

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