问题
I regularly (every few days or so) publish my ASP.NET web project to the local web server.
But the weirdest thing keeps happening... a file called "app_offline.htm" keeps appearing, unbidden, in my web project!
I have deleted this file several times, it is not in source control, and AFAIK nobody else is tampering with the project. But practically every time I try to publish the project, my publish fails (Unable to add 'app_offline.htm' to the Web site. The file 'app_offline.htm' already exists in this Web site.Error: The operation could not be completed. Unspecified error
), I go back to look at the project, and there it is again, large as life, and I suspect if it could it would be blowing raspberries at me. :p
Having read up a little about this file, I gather it's meant to be an easy way to take your app offline. But I didn't see anywhere that it's supposed to impose itself on you arbitrarily for no good reason.
So, where is this *&^%$#@%!! file coming from, and why does VS think I need it?
回答1:
This is a .NET 2.0 "feature"
http://weblogs.asp.net/scottgu/archive/2005/10/06/426755.aspx
http://www.codeproject.com/KB/aspnet/app_offline.aspx
"The easiest way around this is to never publish directly to your server. You shouldn't anyway... Publish to a local folder then copy the site up"
Do you use Visual Studio? http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102778
回答2:
By default the publish process places one in your destination directory but then deletes it when the publish process is done. Perhaps it is being prevented from deleting it when it tries to?
Here is an excerpt from the MSDN article here:
Before you copy application files, the Copy Web Site tool puts a file that is named App_offline.htm into the root directory of the target Web site. While the App_offline.htm file exists, any requests to the Web site are redirected to this file. The file displays a friendly message that tells clients that the Web site is being updated. When all Web site files have been copied, the Copy Web Site tool deletes the App_offline.htm file from the target Web site.
I'd guess that for some reason, there are two publish events somehow conflicting with each other?
The way I get around this is to use nant to build my solution and then copy just the stuff I want. I do indeed copy the app_offline file first, utilizing the feature, but then I manage when it gets copied and deleted.
回答3:
If the Database does not support multiple processes (Exp. SQL Server 2005 express edition or Access). Only single process can access database at a time. So when a database is accessed through visual studio, ASP.net runtime cannot access the database. This will result into the internal server error. To prevent this, VS 2005 places app_offline.htm file in the application's root directory. The file contain above message. This causes ASP.net to put the application in offline mode. Please note the accessing database means opening any component of the database (I.e. table, view, stored procedure etc.) into the design window. When design window is closed, VS 2005 or VS 2008 removes app_offline.htm file making the application in onliner mode again.
Found it here...
来源:https://stackoverflow.com/questions/2148125/why-does-app-offline-htm-keep-appearing-in-my-web-project