I'm trying to create a virtual directory in an asp.net 2 application....and I'm about ready to explode.

My company is hosting several web sites, and I want all of the sites to be able to share a directory of commonly used files, so that I won't have to include all those files with every web site.
This is important to me to save disk space and to make updates as simple as possible.

Each web site has its own application is the IIS (IIS 6.0 on Win2K3) with the following things enabled:
Anonymous acces
Integrated Windows authentication
Local impersonation

Everything's peachy until I create a new virtual directory directly below the application top level.
The virtual directory is automatically configured as an application and shows the contents of the to-be shared folder in IIS alright, but when I run my web site .NET gives me an
"Could not find a part of the path " - Error.

The source folder for the shared virtual directory has read/write acces for the "ASP.NET Machine Account" and "Internet Guest Account".

It seems I've tried everything so any hints/solutions will be greatly appreciated. :cry:

just a thought, but is the shared folder dug down about ten levels in a folder with odd characters or something like that?

Nope.

The folder in which I wanna apply the virtual folder is in level 2 from the web site root.
All folder names are keep "valid"; no spaces, no odd characters (ø etc). Same goes for the to-be virtual folder.

Ahh I think I see whats wrong, try adding an empty folder with the same name as your virtual folder in all your site roots, its an IIS quirk in that virtual directories dont automatically show as physical directories

Naaa, that doesn't do it....unfortunately.

But I just (for once) read the stack trace which says:

[DirectoryNotFoundException: Could not find a part of the path [B]'D:\Sites\mital_danline_dk\http\dnmt\FCKeditor\_dnm\version.txt'.][/B]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +2014176
   System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +998
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) +115
   System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) +85
   System.IO.StreamReader..ctor(String path, Encoding encoding) +16
   System.IO.File.ReadAllLines(String path, Encoding encoding) +93
   System.IO.File.ReadAllLines(String path) +99
   [B]login.Page_Load(Object sender, EventArgs e) in c:\dnm\login.aspx.vb:19[/B]   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

The two bold lines don't "match"....is that right?
The first one is the actual path of the files on the server, the second one is, well, bogus. :?:
(It is the folder 'FCKeditor' I'm trying to add as a virtual directory.)

It looks like a real wild thing this one, I am curious though, why is the app looking for a txt file while loading the login page? Thinking out loud could it be a Forms Authentication redirect problem? When you say the second one is bogus, do you mean the path bears no realtion to where the file physically appears on the Disk? Another question what location (path string) is the application looking at to get to the text file.

When the above error occures the app. is about to load the login-page for a CMS I've been writing.
The text file contains a copyright notice and version info.
This is the first request to files in that directory which mean the application can't see it (I guess).

And yes, I mean that "c:\dnm\login.aspx" doesn't exist. Neither the file nor the folder.

had a similar problem. iis justt refused to work. Try something like Abyss Web Server X1 - it has native ASP.NET 1.1 and 2.0 support

Can't migrate or make significant changes to the server setup.
I have approx. 150 web sites to support - it would be too costly.
There must be someone who has solved a similar problem...

is login.aspx set as the login page in your web.config ?
also, have you used a location section to set authentication properties for the virtual directory?

is login.aspx set as the login page in your web.config ?
also, have you used a location section to set authentication properties for the virtual directory?

No login.aspx isn't configured as the login page. But that's not really mandatory, is it?
Also no, I don't have a location section....in fact I don't think I know what it is.
Can you enlighten me?

<location> section in a web.config lets you set settings for subdirectories in applications, as web.config files are hierachical i.e you can have a web.config file ine ach directory, but the root directory by default overrides the sub directory configs. In your case looking at the stack, there is a call from a class called login.aspx.vb which seems to be performing a read operation on the txt file
If your app is using forms authentication and your web.config file is denying unauthenticated users access to your root directory, then it is possible that this setting is preventing access to your virtual directory. By adding
<location path="FCKeditor">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
that could in theory fix the problem

You're right about the class and the text file but it still won't work.
Putting the <location>-lines in the web.config only returns the well-know Runtime Error instead of the previous error message:

To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

Does the machine.config matter in this?
Also I don't know if this is significant but the structure the web site is:
domain top level
-> asp.net application directory
-> -> this is where I'd like a virtual directory

My web.config now looks like this:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
	<appSettings/>
	<connectionStrings/>
	<locationpath="FCKeditor">
	<system.web>
		<authorization>
			<allowusers="*"/>
		</authorization>
	</system.web>
	</location>
<system.web>
	<identity impersonate="true"/>
	<compilation debug="true" strict="false" explicit="true">
	<assemblies>
	<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
	<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
	</compilation>
<httpRuntime executionTimeout="120" maxRequestLength="20480"/>
	<pages>
		<namespaces>
		<clear/>
	<add namespace="System"/>
	<add namespace="System.Collections"/>
	<add namespace="System.Collections.Specialized"/>
	<add namespace="System.Configuration"/>
	<add namespace="System.Text"/>
	<add namespace="System.Text.RegularExpressions"/>
	<add namespace="System.Web"/>
	<add namespace="System.Web.Caching"/>
	<add namespace="System.Web.SessionState"/>
	<add namespace="System.Web.Security"/>
	<add namespace="System.Web.Profile"/>
	<add namespace="System.Web.UI"/>
	<add namespace="System.Web.UI.WebControls"/>
	<add namespace="System.Web.UI.WebControls.WebParts"/>
	<add namespace="System.Web.UI.HtmlControls"/>
	</namespaces>
	</pages>
<authentication mode="Windows"/>
<customErrors mode="Off" />
</system.web>
</configuration>

Any further ideas? :-|

the location key should go after </system.Web>
and before </configuration>

the error message you have is probably because of the incorrect placing of the location tag

moved the key, same result: runtime error.

I just looked at the code I posted it's missing spaces <locationpath should read:
<location path

and also <allowusers

should read <allow users

sorry about that, I pasted it from a web.config and this editor removed them

Don't worry about it :)
I actually tried inserting the missing space in <location> mysel 'cause I though it didn't look right, but I gues I missed the one in "<allow>"...

Anyway, something did happen: the runtime error went away, and the initial error "Could not find a part of the path..." reoccured...

This is very frustrating. But I do appreciate your help, though, sedgey.
Can you think of anything else to try?

One last stab at this, how are you reading the text file? using Server.MapPath? Try switching off your forms authentication and see if you can access the file by http,

http://yourdomain/virtialfolder/filename.txt

If you can then maybe you can stream the file by http instead of accessing it through the file system. I suspect that the problem lies in the fact that IIS virtual directories may only work for http and ftp only. Anyway, thats my last stab! or one last idea maybe to put these files in new root site of its own and use something like isapi_rewrite to proxy a path like:

http://yourdomain/virtualfolder to http://IPaddressOrDomainOfGlobalFiles

Yep, I can access the file by http - no problem.
In the class I'm referencing the file by

request.physicalapplicationpath & "virtualfolder"

which also returns the correct physical path on the server....that's why I don't it.

The approach of using shared folders like this is used all over the server with "ordinary" asp-sites, so I know it works....just not the my .net2-app.

And I have to do it this way. Textfiles aren't the only files I'd like to access this way...shared app-classes too for one.

Hmmm....I found a way that works.

Initially I mapped the virtual directory and referenced it from the .NET class by physicalApplicationPath & "FCKeditor"....which didn't work. The .NET path output was the physical path of "domain directory"/FCKeditor.

I then left the virtual directory as it were, configured as an application, and reference the directory by Server.MapPath("FCKeditor")....and that works. When I debug it Server.MapPath("FCKeditor") returns the physical path of the virtual directory and the FCKeditor inside the application still works by referencing the source files by just "FCKeditor/".

So the HTML/js read from the virtual directory alright, and previously I etablished that vd has setup alright since I could directory browse it online, but the .NET-code won't allow direct references to the virtual directory.

I think I do see the logic...although somewhat fuzzy :confused:

NOTE: I deleted the <location> keys in web.config just as a test, and it still worked.

BUT that was only step 1/3. Now I want to virtually reference the shared classes as well the same way. So not I get a new error message that says (went back to the not-precompiled version):

The path '/ncdnm/App_Code/' maps to a directory outside this application, which is not supported. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: The path '/ncdnm/App_Code/' maps to a directory outside this application, which is not supported.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[HttpException (0x80004005): The path '/ncdnm/App_Code/' maps to a directory outside this application, which is not supported.]
   System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +3450907
   System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +125
   System.Web.Compilation.BuildManager.CompileCodeDirectories() +525
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +448

[HttpException (0x80004005): The path '/ncdnm/App_Code/' maps to a directory outside this application, which is not supported.]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +57
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +612
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +456

[HttpException (0x80004005): The path '/ncdnm/App_Code/' maps to a directory outside this application, which is not supported.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +3426855
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +88
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +149

Now this I can understand...but I don't know to fix it...yet ;)

I'm trying to create a virtual directory in an asp.net 2 application....and I'm about ready to explode.

My company is hosting several web sites, and I want all of the sites to be able to share a directory of commonly used files, so that I won't have to include all those files with every web site.
This is important to me to save disk space and to make updates as simple as possible.

Each web site has its own application is the IIS (IIS 6.0 on Win2K3) with the following things enabled:
Anonymous acces
Integrated Windows authentication
Local impersonation

Everything's peachy until I create a new virtual directory directly below the application top level.
The virtual directory is automatically configured as an application and shows the contents of the to-be shared folder in IIS alright, but when I run my web site .NET gives me an
"Could not find a part of the path " - Error.

The source folder for the shared virtual directory has read/write acces for the "ASP.NET Machine Account" and "Internet Guest Account".

It seems I've tried everything so any hints/solutions will be greatly appreciated. :cry:

Alright I have figured out a solution! Open the iis mmc console and navigate to the folder that your virtual directory is in....also open windows explorer and navigate to the same directory. This gets weird but i assure you that is works!
first delete your virtual directory.
next create a shortcut (using windows explorer) to the http://address corresponding to the virtual directory.
next switch over to the mmc console and refresh...you'll notice that the .url suffix was added to your shortcut, remove it....i know what your saying but trust me. Now re-create your virtual directory. when you go to your site and click on the link it will append whatever the name of the link is to the end of the http address. I don't know why this works but it does. Make sure that you do the steps in the order i provided because if the virtual directory exists then you will get an error stating the name already exists when you try to delete the .url extension. Let me know if you have any issues interpreting my instructions. You can email me at [snippedl]

Alright I have figured out a solution! Open the iis mmc console and navigate to the folder that your virtual directory is in....also open windows explorer and navigate to the same directory. This gets weird but i assure you that is works!
first delete your virtual directory.
next create a shortcut (using windows explorer) to the http://address corresponding to the virtual directory.
next switch over to the mmc console and refresh...you'll notice that the .url suffix was added to your shortcut, remove it....i know what your saying but trust me. Now re-create your virtual directory. when you go to your site and click on the link it will append whatever the name of the link is to the end of the http address. I don't know why this works but it does. Make sure that you do the steps in the order i provided because if the virtual directory exists then you will get an error stating the name already exists when you try to delete the .url extension. Let me know if you have any issues interpreting my instructions. You can email me at [snipped]

I forgot to add when you create the shortcut name it with the same name of your virtual directory.

I forgot to add when you create the shortcut name it with the same name of your virtual directory.

Hi, dbreise.
If u notice the post dates you'll find that this thread has been dead for more than 2 years now, and no longer has any relevance. But thank you, though ;-)

Hi, dbreise.
If u notice the post dates you'll find that this thread has been dead for more than 2 years now, and no longer has any relevance. But thank you, though ;-)

Yes I understand that. But here it is two years later and I had the same problem. I ended up on this forum but did not find a solution. Other people will have this problem. But they will come here and find the solution!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.