加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 未调用自定义错误页面

发布时间:2020-12-16 04:05:05 所属栏目:asp.Net 来源:网络整理
导读:我需要在MVC 4中实现我自己的自定义错误页面.基本上,当用户尝试查看具有不存在的productID的任何产品的详细信息时,我想要这个自定义错误页面. 我创建了自己的自定义错误页面NotFound.aspx 这个页面的内容是: %@ Page Language="C#" MasterPageFile="~/Views
我需要在MVC 4中实现我自己的自定义错误页面.基本上,当用户尝试查看具有不存在的productID的任何产品的详细信息时,我想要这个自定义错误页面.

我创建了自己的自定义错误页面NotFound.aspx

这个页面的内容是:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Simple.Master" 
Inherits="System.Web.Mvc.ViewPage<System.Web.Mvc.HandleErrorInfo>" %> 
<asp:Content ID="errorTitle" ContentPlaceHolderID="TitleContent" runat="server"> 
Error 
</asp:Content> 
<asp:Content ID="errorContent" ContentPlaceHolderID="MainContent" runat="server"> 
<h2> 
Sorry,you requested a product that doesn't exist. Make sure you
requested a valid ProductID 
</h2> 
</asp:Content>

然后将HandleError过滤器应用于我的ActionMethod:Details as:

[HandleError(View="NotFound")] 
public ActionResult Details(int id) {...

问题是,始终是默认视图:正在调用Views / Shared / Error.aspx,而不是新的自定义错误页面.有什么想法吗 ?

解决方法

试试这个(但我不确定在MVC中使用此代码).将此代码粘贴到web.config文件brlow system.web的配置部分中.
<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
    </customErrors>
    <compilation debug="true" targetFramework="4.0">

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读