954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

IIS .NET2 virtual directory not working

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:

madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

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

sedgey
Junior Poster
131 posts since Jan 2007
Reputation Points: 68
Solved Threads: 9
 

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.

madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

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

sedgey
Junior Poster
131 posts since Jan 2007
Reputation Points: 68
Solved Threads: 9
 

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 <strong>'D:\Sites\mital_danline_dk\http\dnmt\FCKeditor\_dnm\version.txt'.]</strong>
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
<strong>login.Page_Load(Object sender, EventArgs e) in c:\dnm\login.aspx.vb:19</strong> 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.)

madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

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.

sedgey
Junior Poster
131 posts since Jan 2007
Reputation Points: 68
Solved Threads: 9
 

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.

madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

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

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

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...

madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

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?

sedgey
Junior Poster
131 posts since Jan 2007
Reputation Points: 68
Solved Threads: 9
 
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?

madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

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
.web>

that could in theory fix the problem

sedgey
Junior Poster
131 posts since Jan 2007
Reputation Points: 68
Solved Threads: 9
 

You're right about the class and the text file but it still won't work.
Putting the -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 tag within a "web.config" configuration file located in the root directory of the current web application. This 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? :-|

madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

the location key should go after .Web>
and before

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

sedgey
Junior Poster
131 posts since Jan 2007
Reputation Points: 68
Solved Threads: 9
 

moved the key, same result: runtime error.

madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

I just looked at the code I posted it's missing spaces

sedgey
Junior Poster
131 posts since Jan 2007
Reputation Points: 68
Solved Threads: 9
 

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

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?

madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

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

sedgey
Junior Poster
131 posts since Jan 2007
Reputation Points: 68
Solved Threads: 9
 

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 Ihave to do it this way. Textfiles aren't the only files I'd like to access this way...shared app-classes too for one.

madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

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 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 ;)

madmital
Junior Poster
120 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You