Wednesday, March 30, 2011

IIS Express Virtual Directory Set Up

Why IIS Express : You can read detailed benefits of using IIS Express @ http://weblogs.asp.net/scottgu/archive/2010/06/28/introducing-iis-express.aspx

Our Reason of Using IIS Express : We have US developers as well as abroad and every one has different OS on their machines, IIS 7 needs Windows 7 and this was BIGGEST REASON we had to choose IIS 7 Express. Also not all developer will be running VS2010 under Administrative Rights(not at least in day to day development).

----xx----

Get back to the Business of Setting up Virtual Directories :  I spent enough time to research how to set up Virtual Directory so everybody can use same resources while developing code(as usual) but could not get much help(got clues) but not practical example.

But finally found out on my own how to do that. See following steps

1. Download IIS 7 Express (Prerequisite : VS2010 SP1)
2. Start VS2010 and right click on your web project
3. Select "Use IIS Express" from Menu
4. Read the ALERT DIALOGUE and click OK
5. Read other ALERT DIALOGUE asking Your Web project is set to use IIS Express. Click OK
5. Doing this will CREATE a Directory in "C:\My Documents" folder and folder name is 
    "IISExpress" (usually under C:\Users\username\My Documents)
6. Go to IISExpress folder --> Config (folder)
7. You will see ApplicationHost.config file (this file is used by IIS Express for your web project
    when you run it. 
8. Open up ApplicationHost.config file (in any text editor, for better viewing VS2010)
9. This file will have <Sites> section, locate that.
10. Under <Sites> there will be <Site> section containing your Web project Name and looks like
     

<site name="Your Site Name that you selected to run with IIS Express 7" id="1">
 
11. Under this <Site> section you will see something like this
       
        <application path="/" applicationPool="Clr4IntegratedAppPool">
           <virtualDirectory path="/" physicalPath="PHYSICAL PATH WHERE THIS WEB PROJECT IS" />
        </application>
12. Now for example, you want to add Virtual Directory named "myVD" to your project, so
      what you do is, add another virtualDirectory in above snippet, so it would look like following
     
        <application path="/" applicationPool="Clr4IntegratedAppPool">
            <virtualDirectory path="/" physicalPath="PHYSICAL PATH WHERE THIS WEB PROJECT IS" />
            <virtualDirectory path="/myVD" physicalPath="PHYSICAL PATH HERE OF YOUR myVD DIRECTORY" />
        </application>
 
 13. That is it, now you can Refer this "myVD" into your web project or projects if you are
       running your Projects with IIS Express,

       For example, "myVD" holds "myJavaScript.js" file so in your aspx page you will simply refer it like <script src="/myVD/myJavaScript.js" type="text/javascript"></script>

14. Note: Visual Studio 2010 does not know about this "myVD" directory so it will complain
                 that File '/myVD/myJavaScript.js' was not found, but do not worry, it will be taken
                 care of at the RUN TIME by IIS Express.


Regards.