如果不存在操作/控制器,如何显示自定义错误页面? [英] How to show a custom error page if no action/controller exists?

查看:112
本文介绍了如果不存在操作/控制器,如何显示自定义错误页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!



我有一个问题。我是ASP.NET MVC的新手。如果行动路径不正确,有人知道如何显示自定义页面吗?



例如,如果URL类似于 http://www.example。 com / Product / blahhh ,app没有 blahh 操作,我想向用户显示我的自定义错误页面。

Hello!

I have a question. I'm a new in ASP.NET MVC. Does somebody know how to show custom page if path to action is uncorrect?

For example, if the URL is like http://www.example.com/Product/blahhh, and app doesn't have blahh action, and I want to show my custom error page to the user.

推荐答案

ASP.NET中的自定义错误 [ ^ ]

Web.config中的自定义错误模式允许您管理要显示的自定义错误页面。

一般有三种模式:



  • 关闭
  • 开启
  • 仅限远程
<customerrors mode="" defaultredirect="Error/Index">
</customerrors>



另一种方法是:


Another method is:

<customerrors mode="" defaultredirect="">
<error statuscode="400" redirect="NotFound.htm" />
<error statuscode="500" redirect="InternalServerError.htm" />
</customerrors>



请仔细阅读本文,然后您可以将用户重定向到您设计的默认未找到页面。

谢谢

:)


Please go through this article and then you can redirect the user to a default Not Found page designed by you.
Thanks
:)


遗憾的是没有自定义页面,但是有自定义错误页面 ASP.NET。您可以使用自定义错误页面并将用户重定向到应用程序内的自定义错误页面,以便他可以看到错误页面或您尝试向他显示的任何消息。



这是一个关于如何在ASP.NET MVC中创建自定义错误页面的教程, http://benfoster.io/blog/aspnet-mvc-custom-error-pages [ ^ ]。



试一试,你将了解web.config文件和Code Behind的基本实现和用法,以便在出现404错误时使用户移动到自定义页面。



如果目录中找不到资源文件,则会引发Http 404错误。
Sadly there is no thing as a custom page, but there are custom error pages in ASP.NET. You can use custom error pages and redirect the user to your custom error pages inside the application so that he can see the error page or whatever the message you're trying to show to him.

Here is a tutorial on how you can create custom error pages in ASP.NET MVC, http://benfoster.io/blog/aspnet-mvc-custom-error-pages[^].

Give it a try, you will understand the basic implementation and usage of web.config file and the Code Behind to work together to cause the user to move to the custom page if there is a 404 error.

Http 404 error is raised if there is no resource file found in the directory.


这篇关于如果不存在操作/控制器,如何显示自定义错误页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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