IIS部署站點相關經驗總結
1.IIS和.net4.0安裝是有先后順序的,應該先安裝.net framework 4.0,再安裝IIS。如果按相反順序安裝的話,IIS中看不到4.0相關的東西,那么只能執行命令啟用:
C:\Windows\system32> C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_regii.exe -ir -enable
2. IIS的應用程序池標識有“ApplicatonPoolIdentity”,”LocalSystem”,”Local Service”,”Network Service”,默認使用“ApplicatonPoolIdentity”,那么如果你連接的是本地的數據庫,由於安全的限制,你可能就連接不上,在應用程序池高級設置》進程模型中把應用標識改成”LocalSystem”或許就可以了。
3.machineKey : 它默認被配在asp.net 框架級的machine.config(C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config)中, 它默認由.net framework動態生成,在不同的服務器上生成的都不一樣,然而集群場景中必須要一樣才行,不然在一些加密解密過程中會出現錯誤:
4.要注意IIS應用程序池經典模式與集成模式的區別,這個要根據具體場景具體分析。
案例1: 在負載均衡方式部署時,由於多台服務器上的machineKey不一樣,會導致viewstate驗證失敗。
“/”應用程序中的服務器錯誤。
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.
說明: 執行當前 Web 請求期間,出現未經處理的異常。請檢查堆棧跟蹤信息,以了解有關該錯誤以及代碼中導致錯誤的出處的詳細信息。
異常詳細信息: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.
源錯誤:
[沒有相關的源行] |
源文件: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\a59f6e56\410d1464\App_Web_uydhjhqj.5.cs 行: 0
堆棧跟蹤:
案例2: 應用程序池標識設置不當,導致無法連接機上的.\sqlexpress實例
無法打開登錄所請求的數據庫 "wygl"。登錄失敗。
用戶 'IIS APPPOOL\ielong' 登錄失敗。
說明: 執行當前 Web 請求期間,出現未經處理的異常。請檢查堆棧跟蹤信息,以了解有關該錯誤以及代碼中導致錯誤的出處的詳細信息。
異常詳細信息: System.Data.SqlClient.SqlException: 無法打開登錄所請求的數據庫 "wygl"。登錄失敗。
用戶 'IIS APPPOOL\ielong' 登錄失敗。
源錯誤:
執行當前 Web 請求期間生成了未經處理的異常。可以使用下面的異常堆棧跟蹤信息確定有關異常原因和發生位置的信息 |
案例3:v4.0相關的ISAP和CGI擴展未啟用,導致網站無法使用
朋友的產品“易隆物業管理系統”出問題了,就聯系我幫忙解決。我訪問時就遇到下面這個異常信息:
============================2015-07-31 00:12:57==============================
IP:
Message:要處理此請求,必須在配置中注冊 WebResource.axd 處理程序。
<!-- Web.Config 配置文件 -->
<configuration>
<system.web>
<httpHandlers>
<add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
</httpHandlers>
</system.web>
</configuration>
Stack: 在 System.Web.Handlers.AssemblyResourceLoader.GetWebResourceUrlInternal(Assembly assembly, String resourceName, Boolean htmlEncoded, Boolean forSubstitution, IScriptManager scriptManager)
在 System.Web.Handlers.AssemblyResourceLoader.GetWebResourceUrl(Type type, String resourceName, Boolean htmlEncoded, IScriptManager scriptManager)
在 System.Web.UI.ClientScriptManager.GetWebResourceUrl(Page owner, Type type, String resourceName, Boolean htmlEncoded, IScriptManager scriptManager)
在 System.Web.UI.ClientScriptManager.RenderWebFormsScript(HtmlTextWriter writer)
在 System.Web.UI.Page.RenderWebFormsScript(HtmlTextWriter writer)
在 System.Web.UI.Page.BeginFormRender(HtmlTextWriter writer, String formUniqueID)
在 System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)
在 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)
在 System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
在 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
在 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
在 System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer)
在 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
在 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
在 System.Web.UI.Control.Render(HtmlTextWriter writer)
在 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
在 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
在 System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
在 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
在 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
在 System.Web.UI.Page.Render(HtmlTextWriter writer)
在 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
在 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
在 System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
====================================END======================================
想了下,是不是應用程序池類型的原因呢,一看應用程序池現在用的是集成,換成經典試試,
把應用程序池改成經典,然后遇到報錯:
HTTP 錯誤 404.2 - Not Found
由於 Web 服務器上的“ISAPI 和 CGI 限制”列表設置,無法提供您請求的頁面。
然后進入IIS7.5的“ISAPI和CGI限制”,一看明白了,asp.net v4.0處於“不允許”狀態,
把4.0相關的啟用就好了。。。