自定义错误在ASP.NET MVC区域覆盖 [英] Custom errors override in ASP.NET MVC area

查看:117
本文介绍了自定义错误在ASP.NET MVC区域覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有独特的MVC区域自定义错误页。不幸的是,它似乎在Web.config覆盖系统不采取了MVC文件夹结构考虑在内。如果我要重写名为移动的领域,我必须创建一个项目根文件夹(在视图和控制器)命名为移动,并把在Web.config在那里与新的的customErrors 元素。

I would like to have custom error pages unique to an MVC area. Unfortunately, it appears that the Web.config override system doesn't take the MVC folder structure into account. If I want to override an area called "mobile", I have to create a root project folder (in with Views and Controllers) named "mobile" and put the Web.config in there with the new customErrors element.

有一些更好的方式来做到这一点,这样我就不必为任何覆盖创建一个根文件夹?

Is there some better way to do this so that I don't have to create a root folder for any overrides?

推荐答案

我一直在寻找同样的事情。我做一个细微的变化是主要的web.config文件中使用的位置元素。这是preference我想的事,但它让你不必创建您的解决方案中的一个单独的文件夹和文件。我很想知道一个更好的办法,但。

I've been looking for exactly the same thing. One slight change that I do is to use a location element within the main web.config. It's a matter of preference I suppose, but it keeps you from having to create a separate folder and file within your solution. I'd love to know a better way though.

<system.web>
  <customErrors mode="On" defaultRedirect="error" />
</system.web>
.
.
.
<location path="areaName">
  <system.web>
    <customErrors mode="On" defaultRedirect="/areaName/error" />
  </system.web>    
</location>

这篇关于自定义错误在ASP.NET MVC区域覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆