IIS7.5遷移 - HTTP 錯誤 404.0 - Not Found-0x80070002錯誤分析及解決過程

來源:互聯網
上載者:User

標籤:

Asp.net應用遷移到IIS7.5 時,網站報告 HTTP 錯誤 404.0 - Not Found 錯誤。處理過程如下:
運行環境:Framework 2.0,IIS7.5,Web網站一套,沒有原始碼,應用程式集區預設為傳統模式.
報錯頁面的URL如下:http://localhost/HL2008/UI/AutoMonitor/135?autorun=true
看到這個URL地址,第一反應就是HttpModule被重寫了,通過.net reflector 7.0 反編譯HL2008.Web.Common.dll,發現UrlRewriter類,實現了System.Web.IHttpModule介面.
繼續跟蹤,這個類的核心代碼就是一個跳轉操作.

void context_BeginRequest(object sender, EventArgs e)        {            //string path = string.Format("~/Action/RequestHandler.aspx?id={0}&{1}","yeyang",HttpContext.Current.Request.RawUrl);            //HttpContext.Current.RewritePath(path,false);            ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);            log.Info("DemoHttpModule context_BeginRequest 被調用");            string p = string.Empty;            //if (GlobalDefine.IsAutoMon(out p))            if (IsAutoMon(out p))            {                log.Info("DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == true 被調用");                string path = string.Format("~/UI/AutoMonitor/AutoMonitorBasePage.aspx?id={0}&{1}", p, HttpContext.Current.Request.QueryString);                HttpContext.Current.RewritePath(path, false);            }            else            {                log.Info("DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用");            }        }   public static bool IsAutoMon(out string PermissionId)        {            PermissionId = GetPermissionId();            return !string.IsNullOrEmpty(PermissionId);        } public static string GetPermissionId()        {            return GetPermissionId(HttpContext.Current.Request.RawUrl);        }        public static string GetPermissionId(string url)        {            ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);            log.Info("DemoHttpModule GetPermissionId 被調用");            log.Info(string.Format("Url 地址是[{0}]", url));            string PermissionId = string.Empty;            MatchCollection mc = new Regex(@"\/UI\/AutoMonitor\/(?<permissionid>(\d+))(($)|(\?\S+))", RegexOptions.IgnoreCase).Matches(url);            if (mc.Count > 0)            {                return mc[0].Groups["permissionid"].Value;            }            log.Info("在第一個正則匹配之後:mc.Count == 0");            mc = new Regex(@"/UI/AutoMonitor/AutoMonitorBasePage.aspx\?id=(?<permissionid>\d+)", RegexOptions.IgnoreCase).Matches(url);            if (mc.Count > 0)            {                PermissionId = mc[0].Groups["permissionid"].Value;            }            return PermissionId;        }

因此初步判定為HttpModule沒有被啟用,通過網頁搜尋,找到一篇相近的博文(http://q.cnblogs.com/q/38592/),其中提到IIS7.5下 httpModules 使用出現:404 求解決,需要將modules配置增加到<system.webServer>配置節中.
此時的web.config中,在<system.web>下有httpModules和httpHandlers配置,<system.webServer>下有modules和handlers配置.
問題還是沒有解決,通過將增加了log4net日誌的modules組件插接到原有應用程式中輸出的日誌來分析,應用程式在沒有啟用http://localhost/HL2008/UI/AutoMonitor/135?autorun=true這個請求之前就已經終止了.日誌如下:

 - DemoHttpModule context_BeginRequest 被調用2015-01-12 12:41:37,010 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-12 12:41:37,010 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/UI/Security/Main.aspx/FocusHashCode]2015-01-12 12:41:37,010 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-12 12:41:37,010 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用2015-01-12 12:42:01,313 [1276] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-12 12:42:01,313 [1276] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-12 12:42:01,313 [1276] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/UI/Security/Main.aspx/FocusHashCode]2015-01-12 12:42:01,313 [1276] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-12 12:42:01,313 [1276] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用2015-01-12 12:42:06,804 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-12 12:42:06,804 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-12 12:42:06,804 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/UI/Security/Main.aspx/FocusHashCode]2015-01-12 12:42:06,804 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-12 12:42:06,804 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用2015-01-12 12:42:11,921 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-12 12:42:11,921 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-12 12:42:11,921 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/UI/Security/Main.aspx/FocusHashCode]2015-01-12 12:42:11,921 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-12 12:42:11,921 [4084] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用

於是問題就被定義為,modules被調用了,但是並沒有啟用http://localhost/HL2008/UI/AutoMonitor/135?autorun=true這個請求.
繼續,將應用程式集區設定為整合模式,這時候IIS錯誤如下:
HTTP 錯誤 500.22 - Internal Server Error
檢測到在整合的託管管道模式下不適用的 ASP.NET 設定。
模組:ConfigurationValidationModule
通知:BeginRequest
處理常式:StaticFile
錯誤碼:0x80070032
關鍵的資訊如下:
最可能的原因:此應用程式在 system.web/httpModules 節中定義配置。
於是剔除了system.web/httpModules配置節
發起請求,繼續HTTP錯誤,關鍵資訊如下:
?此應用程式在 system.web/httpHandlers 節中定義配置。
剔除system.web/httpHandlers配置節.
發起請求.日誌內容如下:

2015-01-12 22:03:18,058 [6676] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule init 被調用2015-01-12 22:03:18,136 [6676] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-12 22:03:18,136 [6676] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-12 22:03:18,136 [6676] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/UI/AutoMonitor/135?autorun=true]2015-01-12 22:03:18,136 [6676] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == true 被調用

部署到生產環境後,發現架構頁面的JQuery架構失效了.繼續分析.發現架構頁面使用到了ScriptManager控制項,對應產生的Html代碼形如:

<script src="/HL2008/ScriptResource.axd?d=v9-Vun33Q_Tt6fz_-KdfOxFkktcmXkHtJ_xaAlnYyRI1w9v_8zmlGWWHE_7u5Jrvi61k8TbJhxrwk5pWmXh_t7arSi5GkKCo5fRbtk8AocTMmYe-Z7DxXDxZ58VlpPixyBnc59F5eZHs5UV4zWR1dzu8BAU-upWipKdmIR9lgzaYhBED0&t=fffffffff9d85fa6" type="text/javascript"></script><script type="text/javascript"> 

再次檢查web.config檔案,並在webServer中增加以下配置(靈感來自建立web項目時自動產生的程式碼):

<handlers><remove name="WebServiceHandlerFactory-Integrated"/><remove name="ScriptHandlerFactory"/><remove name="ScriptHandlerFactoryAppServices"/><remove name="ScriptResource"/><add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/><add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/><add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>    </handlers>

與上述代碼對應的老的web.config中的配置如下:

<httpHandlers>      <remove verb="*" path="*.asmx" />      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />    </httpHandlers>

修改後的web.config,產生的調試日誌如下:

2015-01-13 17:23:36,107 [6872] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-13 17:23:36,107 [6872] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-13 17:23:36,107 [6872] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/WebResource.axd?d=gzmZlqjdAFh6OdPGsBWp09jjWPrybcivIxB1dm9gbM8VxMISKAXu6a4U2PqImHgLFM7eAwQYHR9YWjCvEdtxcmFt2KUu6k398_VF7VKu6P0hbarkRVBG1v0HhDL3RubSr-FjRA2&t=634134071139291572]2015-01-13 17:23:36,107 [6872] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-13 17:23:36,107 [6872] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用2015-01-13 17:23:36,170 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-13 17:23:36,170 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-13 17:23:36,170 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/ScriptResource.axd?d=N98_-SqLQ5674uNkLlgKa0Owba70UUJIMsXPPAsyT8skc5Y68FcDhDOE2hZO2_Abfm4CJI36eipVEOKx_qvvj5tECsi8ECd2UEcZevylFPlnvkifyGrPKKvzZONnzCSOA-CDsOISCtqpIQkZHcFG1b-8QFs1&t=434e8d85]2015-01-13 17:23:36,170 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-13 17:23:36,170 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用2015-01-13 17:23:36,170 [11096] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-13 17:23:36,170 [11096] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-13 17:23:36,170 [11096] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/ScriptResource.axd?d=v9-Vun33Q_Tt6fz_-KdfOxFkktcmXkHtJ_xaAlnYyRI1w9v_8zmlGWWHE_7u5Jrvi61k8TbJhxrwk5pWmXh_t7arSi5GkKCo5fRbtk8AocTMmYe-Z7DxXDxZ58VlpPixyBnc59F5eZHs5UV4zWR1dzu8BAU-upWipKdmIR9lgzaYhBED0&t=fffffffff9d85fa6]2015-01-13 17:23:36,170 [11096] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-13 17:23:36,170 [11096] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用2015-01-13 17:23:36,170 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule init 被調用2015-01-13 17:23:36,170 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-13 17:23:36,170 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-13 17:23:36,170 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/ScriptResource.axd?d=cNixn-OEPWiQvFR3nFBwBrScpOjRsGp3fK5-H9KtsGrmb5eRvELjuTbsfhOOw80UrKbNl6SQ8-0hshzPc4OU2ynAKKiUHOR-vFpJxtiDz2fm420esofumH2wQGbp5wRVQjPsut_vVJsyCltqoJO2yiIOgA_iWolrD9KQNUVR6IBhOY3U0&t=434e8d85]2015-01-13 17:23:36,170 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-13 17:23:36,170 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用2015-01-13 17:23:36,170 [11096] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-13 17:23:36,170 [11096] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-13 17:23:36,170 [11096] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/ScriptResource.axd?d=GkKeUdwTdRtNhm1Ma1oioEFAgffAgAW_IXjB82oPb2TS8P8ORcSnRzj-mMUHz0DqTyxBwcApwJHW6TtsGFJAg9GUe_PAIQks-Mb5WHwblXUn3u_FGjbGRGIjGbLZP5C05BIa63bIg9F1gYs-gw_xTr8IgDU1&t=434e8d85]2015-01-13 17:23:36,170 [11096] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-13 17:23:36,170 [11096] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/ScriptResource.axd?d=iHAPcT_FVgUzSSekKo0HhOH348ApF9q6M46cXylkg7WB62P5SDfYGAEH8pzg6XDXyS7COBUUOw4Fi-UMAJxKG_ADQ3oE0UkqOshzqC1PcDtV8tbAQJqIN7dSKhFMq7naNJRSkw2&t=434e8d85]2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/WebResource.axd?d=5IPS5otIYO6UJXlB39gOLqh4nEWaX7eoKOZvuIHqSQGUss98IRLKepKPUlZKDz8l9IfSSht6J2qLr8DGuKecSvF1LBM1&t=634259354654344891]2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是<span style="color:#ff0000;">[/HL2008/ScriptResource.axd?d=B0mz6YxA5JQOuXpa0JogyXkEuiSqJXT0qhalr9oqWikr61b8HSaJNPPLphYdrWAcRD2qqxeovdT1vMJ6ZJAoyN4NSKI5R6CqEBMiDY_-KpQ9Q6lkll0eG-QfovrUW1f2A4xfJkZnlNqRzbVG0GKMOqqst59KbZ_eEFL25pKyFJr9Zh-90&t=fffffffff9d85fa6</span>]2015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - 在第一個正則匹配之後:mc.Count == 02015-01-13 17:23:36,185 [10228] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == false 被調用2015-01-13 17:23:37,730 [5544] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest 被調用2015-01-13 17:23:37,730 [5544] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule GetPermissionId 被調用2015-01-13 17:23:37,730 [5544] INFO  Demo.DemoHttpModule [(null)] <(null)> - Url 地址是[/HL2008/UI/AutoMonitor/135?autorun=true]2015-01-13 17:23:37,745 [5544] INFO  Demo.DemoHttpModule [(null)] <(null)> - DemoHttpModule context_BeginRequest -GlobalDefine.IsAutoMon == true 被調用

再次部署到生產環境,問題終於解決.
小結如下:

IIS7.5 404,將system.web中的httpModule註冊到system.webServer的modules,如果應用程式集區是傳統模式,module並沒有正確的啟用.會出現異常終止.
1.只有將應用程式集區切換到整合模式,並徹底剔除掉system.web的httpModules和httpHandlers配置節,才能夠正確啟用module.(如果不移除傳統模式下使用的 httpModules 和 httpHandlers 註冊,則必須將validation 元素的 validateIntegratedModeConfiguration 屬性設定為false 以避免錯誤。)

2.整合模式下,需要將原傳統模式下的system.web下的httpHandlers下的內容遷移到system.webServer下.才能夠保證httpHandlers(asp.net架構層級)能夠正常運行.

ps:感謝csdn的客服,這篇文章在昨天晚上11點左右發布的,今天下午來修改這篇博文時,發現帳號被盜了,且本文也被刪除了,是csnd的客服幫我找回了密碼,並找回了這篇文章,再次表示感謝!!

IIS7.5遷移 - HTTP 錯誤 404.0 - Not Found-0x80070002錯誤分析及解決過程

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.