Tuesday, 17 March 2015

Virtual Directory or Application

When adding ASP.NET pages to a site, you can create a virtual directory (ie a folder), or an application




Virtual Directory

Simple pages will be happy with just a virtual directory, but there are some limitations.





If you create a web project based on a virtual directory (as in the examples given here), you cannot have an app_code folder (or other app_ folders, app_bin etc).  This is because there is only one app_code folder at the root of the web: you aren't allowed to have a second app_code folder inside your virtual directory.

This means you can't use classes in your ASP.NET pages: class files go in the app_code folder.  If you setup a Visual Studio project based on the virtual directory, Visual Studio will let you add a class file, but it will create an app_code folder in your virtual directory to hold it.  This is not the "real" app_code folder, so files here won't be accessible at run time.
If you need to go this way, you could manually copy the contents of the "pseudo" app_code folder to the real app_code folder in the root of the site, but this would be pain to maintain.

You could point your webproject at the root of the sharepoint site … but this is probably not a good idea.


Application

An application however (is still a folder) but it can have it's own app_code (Etc) folder and this can contain class files.
So having a Visual Studio project on an application folder works OK.  You can create classes, put them in the app_Code folder and call the class as usual.




Which?


• I think, generally Visual Studio projects should be an application - this allows you to use classes etc as you should
• I have not -yet- found any disadvantages to using an application


See also http://www.iis.net/learn/get-started/planning-your-iis-architecture/understanding-sites-applications-and-virtual-directories-on-iis 

No comments:

Post a Comment