Windows-Server-2008

在維護期間用靜態頁面替換活動站點的最簡單方法?

  • November 19, 2010

好吧,伙計們,

只是想了解一下其他人在以下場景中使用的方法……

我有一個實時(.net 3.5)項目,它從 IIS7 的預設文件夾(映射到已發布的 wwwroot 文件夾的“根”)執行。當我們進行維護或升級時(通過 VS 內置的 windows 安裝程序),我通常用靜態頁面替換應用程序來解釋系統正在維護中。

我們將發布的站點移動到一個子目錄(我們也沒有安裝它),刪除舊版本,安裝新版本,當我們滿意時,將它移回根目錄(替換保留頁面)。

必須有一種更簡單、風險更低的方法來做到這一點。

其他人如何處理這種(或類似的)情況?

在 IIS 中,我使用一種稱為 App_Offline 的方法。更多資訊可以在Scott Gu 的部落格上找到。

app_offline.htm 的工作方式是將此文件放在應用程序的根目錄中。當 ASP.NET 看到它時,它將關閉應用程序的應用程序域(而不是為請求重新啟動它),而是發回 app_offline.htm 文件的內容以響應應用程序的所有新動態請求。完成網站更新後,只需刪除文件,它就會重新上線。

我在演講中指出了您要關注的一件事是 IE6 的一項功能,稱為“顯示友好的 Http 錯誤”。這可以在 IE 中的工具->Internet 選項->高級選項卡中進行配置,並且預設情況下在 IE6 中處於啟用狀態。當它打開時,伺服器返回一個內容少於 512 字節的非 HTTP-200 狀態程式碼,IE 將不會顯示返回的 HTML,而是替換它自己的通用狀態程式碼消息(我個人認為這不是超級友好 )。

因此,如果您使用 app_offline.htm 功能,您應該確保其中包含至少 512 字節的內容,以確保您的 HTML(而不是 IE 的友好狀態消息)顯示給您的使用者。如果您不想在頁面上顯示大量文本,您可以使用的一個技巧是添加一個帶有一些虛假內容的 html 客戶端註釋,將其推送到 512 字節以上。例如:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>Site Under Construction</title>
</head>
<body>
   <h1>Under Construction</h1>

   <h2>Gone to Florida for the sun...</h2>

<!--       
   Adding additional hidden content so that IE Friendly Errors don't prevent
   this message from displaying (note: it will show a "friendly" 404
   error if the content isn't of a certain size).

   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2> 
   <h2>Gone to Florida for the sun...</h2>     
-->
</body>
</html>

在我們的姊妹網站StackOverflow上進行更多討論。

引用自:https://serverfault.com/questions/203893