Special Directories in ASP.NET 2.0

Tuesday, June 28, 2005

ASP.NET 2.0 introduces a number of special directories for application resources. These directories live as subfolders in the application root, have special names, and offer various shortcuts and conveniences to web developers. One such folder is the App_Code folder. You can drop a .cs file into the App_Code folder, even while an application is running, and the runtime will automatically compile all the code inside the folder into an assembly.

The App_Code folder is one of those features experienced developers will shun in favor of class libraries. Other folders have definite advantages. For example, the App_Browsers folder will allow you to update browser definitions (browsercaps) for an application. In a shared hosting environment today, you’d have to clutter up web.config with new browsercaps. There are also special directories for skin files (App_Themes), resource files (App_GlobalResources, App_LocalResources, App_Resources), and web references (App_WebReferences). As always, the trusty Bin directory will also be around.

Then there is App_Data. You can plop SQL Server data (.mdf) and log files (.ldf) into the directory, and have the engine attach dynamically by using AttachDBFileName in the connection string. App_Data will be a useful feature for people in shared hosting environments, where XCOPY and FTP deployment options are the only options available.

I think App_Data is a double-edged sword. Under the right conditions, you’ll be able to overwrite a production database with an FTP client. Ouch.


Comments
Johannes Hansen Friday, November 11, 2005
Mr. Allen wrote: "Under the right conditions, you’ll be able to overwrite a production database with an FTP client. Ouch."

True, but I don't think I would want to run ANY professional DB in this way. Also, if the DB is being used this file is most likely being locked på the SQL server process, but yes it could happen. Ouch indeed... .NET 2.0 have a lot of hobbyist features that won't be that useful in a real production system.
anonymous email Friday, October 13, 2006
It is important to know that the The App_Data useful if you want to exclude files from compiling. In VS 2003 you could exclude folders from a project but you can't anymore exculde folder in VS2005.

In case you have a folder with tons of files, VS 2005 will be terrible slow since it compiles this data as well. If you place it into the App_Data folder, things will work smoothly ;)
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!