ASP.NET Development Server and Linking to Remote Shares using Symbolic Links
February 25, 2010 2 Comments
In one of our recent eCommerce projects, we needed to access images stored on a network share within our website hosted on the ASP.NET development web server.
By default, the ASP.NET web server does not allow you to add virtual directories like IIS does. This article will give you the steps to find your way around this problem
Our scenario deals with a web project in Visual Studio. The site uses some images stored on a network share. It is not effective to download and store all these images locally. When users access the site, the images should be loaded directly from the network share. For (e.g) When you access http://customsite/images/image1.jpg , the web server assumes that you have a images directory underneath your webroot and will look for a image1.jpg file.
When users access the site, we need to pull image1.jpg from a network share. The technique to achieve this is really simple if you are using Windows Vista/7/Windows Server 2008.
Symbolic Links are a core feature of these later editions of Windows and help us achieve the above
Read more about Symbolic Links
Step1: Map a network drive to the remote network share.
Map the network share location that has the images to a drive letter in Windows
Step 2: Create a Symbolic Link using the mklink command
In our example, when the user requests an image it is loaded from the images folder. This images folder is supposed to be found by the ASP.NET web server under the root folder of your web application. For e.g. if your web application is located under “C:\inetpub\wwwroot\webapplication1” then your images folder is usually under the webapplication1 folder.
Important Tip: Do not create the images folder manually and try to map to the network share. Mklink will do that for you
Open a command prompt as an administrator
Type the mklink command as follows
mklink /d “Your Image Folder under your webroot” “Mapped Network Drive Location”
In our example, it will be
mklink /d “C:\inetpub\wwwroot\webapplication1\images” W:\
Now you should see Windows Create a Symbolic link to the network share.
Browse to the site and you should see your images loaded from the network share
Important Tip: Be very careful, when deleting the Symbolic linked folder. You will be deleting the underlying files on the network share