在asp.net mvc2中怎么设置有错误时导航到指定的页面,高分求教

xuexiaodong2009
博客专家认证
2011-06-02 09:36:07
在asp.net mvc2中怎么设置有错误时导航到指定的页面

首先声明:配置文件的方式是不行的
<customErrors mode="on"></customErrors>

其次在Global的Application_Error事件处理中某些错误也不会导航到通过Controller控制的错误页面,例如一个连接到PDF文件的链接,在没有PDF文件时,通过Controller没有导航到希望的错误页面。
再次,mvc2真的没全局过滤器
必须使用特性那种方式吗?一百个action,就得给这一百个action都要加上这个错误处理的特性吗?
没有在配置文件里配置一次就可以的简单方法吗?


原帖
http://topic.csdn.net/u/20110601/13/dfcc4652-fd51-4491-8c87-4d30e6295e73.html
...全文
138 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuexiaodong2009 2011-06-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 foren_whb 的回复:]

引用楼主 xuexiaodong2009 的回复:

首先声明:配置文件的方式是不行的
<customErrors mode="on"></customErrors>


什么叫"配置文件的方式是不行的"

?????

你的错误页面指定没?
错误页面的路径指定正确没??
[/Quote]配置文件确实可以,是自己搞错了
子夜__ 2011-06-02
  • 打赏
  • 举报
回复
MARK一下 好使不。
xuexiaodong2009 2011-06-02
  • 打赏
  • 举报
回复
为什么在本地可以转到指定的错误页面,发布后就不行了?
丰云 2011-06-02
  • 打赏
  • 举报
回复
[Quote=引用楼主 xuexiaodong2009 的回复:]

首先声明:配置文件的方式是不行的
<customErrors mode="on"></customErrors>

[/Quote]
什么叫"配置文件的方式是不行的"

?????

你的错误页面指定没?
错误页面的路径指定正确没??
丰云 2011-06-02
  • 打赏
  • 举报
回复
webconfig里面:

</roleManager>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="On" defaultRedirect="~/ErrorPage/Error" >
</customErrors>
-->
<pages>


==>>


</roleManager>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
-->
<customErrors mode="On" defaultRedirect="~/ErrorPage/Error" >
</customErrors>

<pages>

62,054

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧