我怎样才能使ASP.NET网页都与WebMatrix中自定义错误页? [英] How can I make a custom error page in ASP.NET web-pages with WebMatrix?

查看:196
本文介绍了我怎样才能使ASP.NET网页都与WebMatrix中自定义错误页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

信不信我试图寻找答案用一个简单的谷歌搜索这个问题,但我没有发现任何东西(用WebMatrix中自定义错误页Google搜索,WebMatrix中如何自定义服务器端错误页面等),但也许我不会用正确的字词进行搜索...

Believe it or not I tried to look for the answer to this question with a simple Google Search but I didn't find anything (Googled with "WebMatrix custom error page", "WebMatrix how to make custom server-side error page", etc.), but perhaps I am not searching with the correct terms...

不管怎样,我只是想知道如果有一种方法(我相信它涉及到的web.config 文件),以显示一个定制的错误页面,而不是 ANY 的服务器端错误页面。

Anyway, I was just wondering if there was a way (I believe it involves the web.config file) to show a custom-made error page instead of ANY server-side error page.

我知道有一种方法与某些页面(如404或500),要做到这一点,但它可能使一个包罗万象的页面,任何服务器端错误? (我想404是行不通的,因为它必须找到你的网站显示的任何自定义页面?)

I know there is a way to do this with some pages (like 404 or 500) but is it possible to make a catch all page for any server-side error? (I guess 404 wouldn't work, since it has to find your site to show any custom page?)

请原谅我,如果这是一个重复的问题,但我在做这个知识的缺乏可能已经离开我没有正确的搜索词进行搜索时,虽然我试图寻找SE,以及

Please forgive me if this is a repeat question, but my lack of knowledge in doing this has possibly left me without the correct search terms to search on, although I have tried searching SE, as well.

推荐答案

以下内容添加到您在web.config文件的<&的System.Web GT; 节点:

Add the following to your web.config file within the <system.web> node:

<customErrors mode="On" defaultRedirect="~/Error.cshtml" />

这将用户重定向到Error.cshtml(你需要创建)在任何ASP.NET错误事件。您可以在开发过程中改变模式值仅限远程,这样就可以看到实际的错误消息。

This will redirect the user to Error.cshtml (which you need to create) in the event of any ASP.NET error. You can change the mode value to RemoteOnly during development, so that you can see the actual error message.

如果你想有一个自定义的404页,以及,你可以做到以下几点:

If you want a custom 404 page as well, you can do the following:

<customErrors mode="On">
    <error statusCode="500" redirect="~/Error.cshtml" />
    <error statusCode="404" redirect="~/404.cshtml" />
</customErrors>

这篇关于我怎样才能使ASP.NET网页都与WebMatrix中自定义错误页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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