Wednesday, January 16, 2013

Mystery behind app_offline.htm file is solved!!!


What is app_offline.htm file?
Asp.net framework avail offline mode of web application to perform some update and data transfer operation on production server.In offline mode application does not respond to request made for dynamic web page.So,when a request for web page is made from an application in offline mode,it return error message to the user which states:

"This application is currently offline.To enable the application, remove the app_offline.htm file from the application root directory."

Above error message is returned to user using app_offline.htm file.Therefore,app_offline.htm file is used to send customized error message to all user who request dynamic pages from application in offline mode.

How app_offline.htm file is created?
SQL Server 2005 express edition and its superceded editions does not support multiple processes.Only single process can access database at a one time.So,when database is accessed through visual studio, visual studio's integrated web server,also known as cassini cannot access database.This will result to internal server error.To prevent these,visual studio places app_offline.htm file under the root of your web application,which put your application in offline mode.










Tuesday, January 15, 2013

What is DataDirectory in Asp.net?

In Asp.net, DataDirectory (which is enclosed in a pipe symbol in a connection string) is a replacement string which indicate path to your database file and also eliminate the need to hard-code the full path to your database file as .

By default DataDirectory refers to  App_Data folder under the root of your web application.For Desktop application, DataDirectory points to bin directory.So,now the question is what is we wanted DataDirectory to point to a different location(other than App_Code folder)?

The issue can be resolved using AppDomain.And the following line will set DataDirectory path before using it in connection string.

AppDomain.CurrentDomain.setData("DataDirectory",@"c:\Data\");

That would make your DataDirectory to point to "c:\Data\database.mdf path.