C# 在 Umbraco CMS 中创建自定义错误页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/140137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a custom error page in Umbraco CMS
提问by Gthompson83
I'm working on a client site who is using Umbraco as a CMS. I need to create a custom 404 error page. I've tried doing it in the IIS config but umbraco overrides that.
我正在使用 Umbraco 作为 CMS 的客户站点上工作。我需要创建一个自定义的 404 错误页面。我试过在 IIS 配置中这样做,但 umbraco 覆盖了它。
Does anyone know how to create a custom 404 error page in Umbraco? Is there a way to create a custom error page for runtime errors?
有谁知道如何在 Umbraco 中创建自定义 404 错误页面?有没有办法为运行时错误创建自定义错误页面?
回答by Swati
In /config/umbracoSettings.config
modify <error404>1</error404>
"1" with the id of the page you want to show.
在/config/umbracoSettings.config
修改<error404>1</error404>
“ 1”与你想显示的页面的ID。
<errors>
<error404>1</error404>
</errors>
Other ways to do it can be found at Not found handlers
其他方法可以在Not found handlers 中找到
回答by Dirk De Grave
umbraco also supports culture dependent error pages in case you're working with multilingual sites...
umbraco 还支持文化相关的错误页面,以防您使用多语言网站...
Config changes a tiny bit. Instead of
配置略有变化。代替
<errors>
<error404>1050</error404>
</errors>
you'd now write
你现在会写
<errors>
<errorPage culture="default">1</errorPage>-->
<errorPage culture="en-US">200</errorPage>-->
</errors>
Cheers, /Dirk
干杯,/德克
回答by Shri Ganesh
First create an error page (and template) in your umbraco installation. Let us say error.aspx. Publish it. Then edit config/umbracoSettings.config.
首先在您的 umbraco 安装中创建一个错误页面(和模板)。让我们说error.aspx。发布它。然后编辑config/umbracoSettings.config。
Under <errors> section
<error404>1111</error404>
Where 1111is the umbraco node IDfor the error.aspx page
其中1111是error.aspx 页面的umbraco 节点 ID
Node ID can be found by hovering mouse on the error node in contentsection. It's usually a 4 digit number.
可以通过将鼠标悬停在内容部分中的错误节点上来找到节点 ID 。它通常是一个 4 位数字。
Then edit the web.config:
然后编辑web.config:
In <appSettings> section
change <customErrors mode as show below:
<customErrors mode="RemoteOnly" defaultRedirect="~/Error.aspx"/>
回答by marapet
Currently umbracoSettings.conf
has to be configured the following way in order to make it work in a multilingual way:
目前umbracoSettings.conf
必须按以下方式配置才能使其以多语言方式工作:
<errors>
<!-- the id of the page that should be shown if the page is not found -->
<!-- <errorPage culture="default">1</errorPage>-->
<!-- <errorPage culture="en-US">200</errorPage>-->
<error404>
<errorPage culture="default">1</errorPage>
<errorPage culture="ru-RU">1</errorPage>
<errorPage culture="en-US">2</errorPage>
</error404>
</errors>
Please note the error404
element which surrounds the errorPage
elements, as well as the comments omitting this small yet important detail...
请注意error404
围绕errorPage
元素的元素,以及省略这个小而重要的细节的评论......
回答by Sprague
As stated by other posters, modify the errors section as indicated (including culture if needed.) In addition, add the following in the web config to enable passthrough of errors to umbraco:
正如其他海报所述,按照指示修改错误部分(如果需要,包括文化。)此外,在 web 配置中添加以下内容以启用错误传递到 umbraco:
In /config/umbracoSettings.config (the file itself explains its usage):
在 /config/umbracoSettings.config (文件本身解释了它的用法):
<errors>
<!-- the id of the page that should be shown if the page is not found -->
<!-- <errorPage culture="default">1</errorPage>-->
<!-- <errorPage culture="en-US">200</errorPage>-->
<error404>2664</error404>
</errors>
In /web.config
在 /web.config
<system.webServer>
<!-- Some other existing stuff -->
<httpErrors existingResponse="PassThrough" />
</system.webServer>
(Note: This is .NET 4)
(注意:这是 .NET 4)