久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      深入解析asp.net中mvc4自定義404頁(yè)面(分享)

      之前的文章《一文講解JS中ES6代理Proxy用法(代碼分享)》中,給大家了解了JS中ES6代理Proxy用法。下面本篇文章給大家了解asp.net中mvc4自定義404頁(yè)面,有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對(duì)你們有所助。

      深入解析asp.net中mvc4自定義404頁(yè)面(分享)

      定義404方法當(dāng)然有很多種。不同的方法所展現(xiàn)的形式也不一樣,用戶所體驗(yàn)也不一樣。以下提供 2 兩種

      方法一

      1、在web.config中找到節(jié)<system.web>點(diǎn)中啟用404配置

      <customErrors defaultRedirect="~/Error" mode="On" redirectMode="ResponseRedirect"> <error redirect="/Error" statusCode="404" /> </customErrors>

      2、定義一個(gè)controllersError(這個(gè)隨你) ,在action中如下定義

      public ActionResult Index() {     Response.Status = "404 Not Found";     Response.StatusCode = 404;     return View(); }

      這種方式默認(rèn)為給你的url加上?aspxerrorpath=/比如:http://localhost/Error??aspxerrorpath=/123456故不推薦試用

      方法二:

      打開(kāi)Global.asax文件定義錯(cuò)誤轉(zhuǎn)向地址(controller/action)

      protected void Application_Error(object sender, EventArgs e) {     Exception ex = Server.GetLastError();     if (ex is HttpException && ((HttpException)ex).GetHttpCode() == 404)     {         Response.Redirect("/Error");     } }

      注意事項(xiàng): 在開(kāi)發(fā)時(shí)候,我們經(jīng)常會(huì)在Global.asax中的Application_Error方法中使用Response.Redirect方法跳轉(zhuǎn)到自定義錯(cuò)誤頁(yè),但有時(shí)候(特別是當(dāng)站點(diǎn)部署到 IIS 后)Application_Error方法中使用Response.Redirect方法會(huì)失效,當(dāng)發(fā)生異常錯(cuò)誤后還是顯示的默認(rèn)錯(cuò)誤黃頁(yè)。

      其根本原因是盡管我們?cè)?code>Application_Error方法中使用了Response.Redirect方法,但是當(dāng)系統(tǒng)發(fā)生異常錯(cuò)誤后Asp.Net認(rèn)為異常并沒(méi)有被處理,所以不會(huì)跳轉(zhuǎn)到Application_Error方法中Response.Redirect指向的頁(yè)面,最終還是會(huì)跳轉(zhuǎn)到默認(rèn)錯(cuò)誤黃頁(yè)。

      解決這個(gè)問(wèn)題的辦法很簡(jiǎn)單就是在Application_Error方法中使用Response.Redirect做跳轉(zhuǎn)前,先調(diào)用Server.ClearError()方法告訴系統(tǒng)發(fā)生的異常錯(cuò)誤已經(jīng)被處理了,這樣再調(diào)用Response.Redirect方法系統(tǒng)就會(huì)跳轉(zhuǎn)到自定義錯(cuò)誤頁(yè)面了。

      推薦學(xué)習(xí):asp.net視頻教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)