第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使自定義錯誤頁在ASP.NETMVC 4中工作

如何使自定義錯誤頁在ASP.NETMVC 4中工作

嚕嚕噠 2019-07-08 15:46:23
如何使自定義錯誤頁在ASP.NETMVC 4中工作我希望為500,404和403顯示一個自定義錯誤頁面。以下是我所做的:已啟用web.config中的自定義錯誤,如下所示:<customErrors mode="On"                defaultRedirect="~/Views/Shared/Error.cshtml">     <error statusCode="403"             redirect="~/Views/Shared/UnauthorizedAccess.cshtml" />     <error statusCode="404"             redirect="~/Views/Shared/FileNotFound.cshtml" /></customErrors>注冊HandleErrorAttribute中的全局操作篩選器。FilterConfig類別如下:public static void RegisterGlobalFilters(GlobalFilterCollection filters){     filters.Add(new CustomHandleErrorAttribute());     filters.Add(new AuthorizeAttribute());}為上述每條消息創(chuàng)建自定義錯誤頁。500的默認選項已經(jīng)可用。在每個自定義錯誤頁視圖中聲明為System.Web.Mvc.HandleErrorInfo對于500,它顯示自定義錯誤頁面。對其他人來說并非如此。我遺漏了什么嗎?這看起來并不是顯示自定義錯誤的全部內(nèi)容,因為我在OnException方法HandleErrorAttribute類,并且它僅處理500個。我要怎么做才能處理其他錯誤?
查看完整描述

3 回答

?
守著星空守著你

TA貢獻1799條經(jīng)驗 獲得超8個贊

我的當前設(shè)置(在MVC 3上,但我認為它仍然適用)依賴于有一個ErrorController,所以我用:

<system.web>
    <customErrors mode="On" defaultRedirect="~/Error">
      <error redirect="~/Error/NotFound" statusCode="404" />
    </customErrors></system.web>

控制器包含以下內(nèi)容:

public class ErrorController : Controller{
    public ViewResult Index()
    {
        return View("Error");
    }
    public ViewResult NotFound()
    {
        Response.StatusCode = 404;  //you may want to set this to 200
        return View("NotFound");
    }}

視圖就是你實現(xiàn)它們的方式。不過,我傾向于添加一些邏輯,以便在應用程序處于調(diào)試模式時顯示堆棧跟蹤和錯誤信息。所以Error.cshtml看起來如下所示:

@model System.Web.Mvc.HandleErrorInfo
@{
    Layout = "_Layout.cshtml";
    ViewBag.Title = "Error";
}<div class="list-header clearfix">
    <span>Error</span></div><div class="list-sfs-holder">
    <div class="alert alert-error">
        An unexpected error has occurred. Please contact the system administrator.    </div>
    @if (Model != null && HttpContext.Current.IsDebuggingEnabled)
    {        <div>
            <p>
                <b>Exception:</b> @Model.Exception.Message<br />
                <b>Controller:</b> @Model.ControllerName<br />
                <b>Action:</b> @Model.ActionName            </p>
            <div style="overflow:scroll">
                <pre>
                    @Model.Exception.StackTrace                </pre>
            </div>
        </div>
    }</div>


查看完整回答
反對 回復 2019-07-08
?
慕森王

TA貢獻1777條經(jīng)驗 獲得超3個贊

我做了巴勃羅的解決方案,我總是有錯誤(MVC4)

未找到視圖“錯誤”或其母版,或者沒有視圖引擎支持搜索的位置。

為了擺脫這個,拆線

 filters.Add(new HandleErrorAttribute());

在FilterConfig.cs中


查看完整回答
反對 回復 2019-07-08
?
犯罪嫌疑人X

TA貢獻2080條經(jīng)驗 獲得超4個贊

我所做的事情,需要比其他解決方案更少的編碼張貼。

首先,在我的web.config中,我有以下內(nèi)容:

<customErrors mode="On" defaultRedirect="~/ErrorPage/Oops">
   <error redirect="~/ErrorPage/Oops/404" statusCode="404" />
   <error redirect="~/ErrorPage/Oops/500" statusCode="500" /></customErrors>

控制器(/Controller/ErrorPageController.cs)包含以下內(nèi)容:

public class ErrorPageController : Controller{
    public ActionResult Oops(int id)
    {
        Response.StatusCode = id;

        return View();
    }}

最后,視圖包含以下內(nèi)容(為簡化,但它可以包含以下內(nèi)容:

@{ ViewBag.Title = "Oops! Error Encountered"; }


<section id="Page">

  <div class="col-xs-12 well">

    <table cellspacing="5" cellpadding="3" style="background-color:#fff;width:100%;" class="table-responsive">

      <tbody>

        <tr>

          <td valign="top" align="left" id="tableProps">

            <img width="25" height="33" src="~/Images/PageError.gif" id="pagerrorImg">

          </td>

          <td width="360" valign="middle" align="left" id="tableProps2">

            <h1 style="COLOR: black; FONT: 13pt/15pt verdana" id="errortype"><span id="errorText">@Response.Status</span></h1>

          </td>

        </tr>

        <tr>

          <td width="400" colspan="2" id="tablePropsWidth"><font style="COLOR: black; FONT: 8pt/11pt verdana">Possible causes:</font>

          </td>

        </tr>

        <tr>

          <td width="400" colspan="2" id="tablePropsWidth2">

            <font style="COLOR: black; FONT: 8pt/11pt verdana" id="LID1">

                            <hr>

                            <ul>

                                <li id="list1">

                                    <span class="infotext">

                                        <strong>Baptist explanation: </strong>There

                                        must be sin in your life. Everyone else opened it fine.<br>

                                    </span>

                                </li>

                                <li>

                                    <span class="infotext">

                                        <strong>Presbyterian explanation: </strong>It's

                                        not God's will for you to open this link.<br>

                                    </span>

                                </li>

                                <li>

                                    <span class="infotext">

                                        <strong> Word of Faith explanation:</strong>

                                        You lack the faith to open this link. Your negative words have prevented

                                        you from realizing this link's fulfillment.<br>

                                    </span>

                                </li>

                                <li>

                                    <span class="infotext">

                                        <strong>Charismatic explanation: </strong>Thou

                                        art loosed! Be commanded to OPEN!<br>

                                    </span>

                                </li>

                                <li>

                                    <span class="infotext">

                                        <strong>Unitarian explanation:</strong> All

                                        links are equal, so if this link doesn't work for you, feel free to

                                        experiment with other links that might bring you joy and fulfillment.<br>

                                    </span>

                                </li>

                                <li>

                                    <span class="infotext">

                                        <strong>Buddhist explanation:</strong> .........................<br>

                                    </span>

                                </li>

                                <li>

                                    <span class="infotext">

                                        <strong>Episcopalian explanation:</strong>

                                        Are you saying you have something against homosexuals?<br>

                                    </span>

                                </li>

                                <li>

                                    <span class="infotext">

                                        <strong>Christian Science explanation: </strong>There

                                        really is no link.<br>

                                    </span>

                                </li>

                                <li>

                                    <span class="infotext">

                                        <strong>Atheist explanation: </strong>The only

                                        reason you think this link exists is because you needed to invent it.<br>

                                    </span>

                                </li>

                                <li>

                                    <span class="infotext">

                                        <strong>Church counselor's explanation:</strong>

                                        And what did you feel when the link would not open?

                                    </span>

                                </li>

                            </ul>

                            <p>

                                <br>

                            </p>

                            <h2 style="font:8pt/11pt verdana; color:black" id="ietext">

                                <img width="16" height="16" align="top" src="~/Images/Search.gif">

                                HTTP @Response.StatusCode - @Response.StatusDescription <br>

                            </h2>

                        </font>

          </td>

        </tr>

      </tbody>

    </table>

  </div>

</section>

運行代碼段展開片段

就這么簡單。它可以很容易地擴展到提供更詳細的錯誤信息,但是ELMAH為我處理這個問題&StatusCode&StatusDescription是我通常需要的。



查看完整回答
反對 回復 2019-07-08
  • 3 回答
  • 0 關(guān)注
  • 302 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號