Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In IIS6 you can't setup the App_Code directory as a virtual directory.

However, I found that you can setup a virtual directory within the App_Code directory and IIS6 will compile the code into the __code assembly.

It seems that IIS7 won't do this, but I wonder if there is a different way to share a code directory across multiple sites in IIS7.

One option that does work is to create a Junction to the common source code directory, but I really enjoyed having the virtual directory option and by definition the code automatically inaccessible via FTP.

share|improve this question
up vote 2 down vote accepted

Recommended? probably not. Illegal? maybe. Possible? yes.

You can use virtual directories in the App_Code directory of an ASP.Net file-based website hosted in IIS7.

Create the empty path on disk

First, create a file structure similar to the path below, where "MyWebRoot" is the root directory of your website and "MySharedCode" is the name you want for the virtual directory that will contain the shared *.cs or *.vb source code files.


Mask the physical path with the virtual directory

Next, open the Internet Information Services (IIS) Manager and find your site under the "Sites" node of the server.

Click the plus next to the site name to expand the site. You will see the top level directories listed.

Right-click on the "App_Code" directory and choose "Add Virtual Directory..." (See screenshot)

IIS Virtual Directory Dialog Screenshot

Type the name of your shared code virtual directory into the "Alias" text box. This name must match the name of the empty folder you created in the App_Code directory.

Finally, enter the actual path to the shared code location in the "Physical path" text box.

Click "OK" to finish creating the virtual directory.

The next time you browse the site, IIS should compile the files located in the physical path that your virtual directory references.

NOTE: You may need to reset IIS or "touch" the Web.Config file to kickstart that process.

Start > Run > iisreset

Apparently, IIS gives precedence to the content of the virtual directory but it needs the presence of the physical path to motivate it to compile.

share|improve this answer

So why wouldn't you compile the code that you want in your shared App_Code and install it in the GAC? That's what its there for, and much more secure than what you're proposing.

share|improve this answer
Microsoft created the compile on demand website concept and this is the customer's preferred deployment strategy. We may have to compile, but I am curious if this can be done in IIS7 like it could be in IIS6. – jedatu Sep 4 '09 at 2:54
While compile on demand certainly looks nice, as soon as you start sharing assemblies like this, the GAC is a much nicer solution. – Christopher_G_Lewis Sep 4 '09 at 14:18
So are you saying that it can't be done or you don't know? – jedatu Sep 4 '09 at 20:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.