我正在使用CodeIgniter的模板库,http: //williamsconcepts.com/ci/codeigniter/libraries/template/reference.html,现在我也想实现自定义错误页面.我找到了一个涉及MY_Router扩展默认路由器的方法:http://maestric.com/doc/php/codeigniter_404 但只处理404错误.我希望所有错误都显示一个简单的用户友好页面,包括数据库错误等,我希望它通过一个控制器,部分所以我可以使用模板库,部分所以我也可以实现一个电子邮件功能来发送自己有关发生的错误的信息.
有人问过将上述MY_Router方法的功能扩展到其他错误,比如error_db,但没有得到作者的回答,所以我转到这里看看是否有人知道如何做到这一点,按照上述方法或实现它的任何其他简单方法.请注意我是新手,所以不要过多地考虑我对基本CodeIgniter功能的了解:-)
我的 MVC3 应用程序显示 403、404 和 500 状态代码的自定义错误页面,但浏览到 trace.axd 会显示以下 YSOD:
Server Error in '/' Application.
Trace Error
Description: Trace.axd is not enabled in the configuration file for this application. Note: Trace is never enabled when <deployment retail=true />
Details: To enable trace.axd, please create a <trace> tag within the configuration file located in the root directory of the current web application. This <trace> tag should then have its "enabled" attribute set to "true".
<configuration>
<system.web>
<trace enabled="true"/>
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
所以我禁用了跟踪,这很好,但是为什么没有显示 …
我的问题是关于Pure.Kromes对这篇文章的回答.我尝试使用他的方法实现我的页面的自定义错误消息,但有些问题我无法解释.
a)当我通过输入无效的URL(例如localhost:3001/NonexistantPage)引发404错误时,它默认为我的错误控制器的ServerError()Action,即使它应该转到NotFound().这是我的ErrorController:
public class ErrorController : Controller
{
public ActionResult NotFound()
{
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = (int)HttpStatusCode.NotFound;
var viewModel = new ErrorViewModel()
{
ServerException = Server.GetLastError(),
HTTPStatusCode = Response.StatusCode
};
return View(viewModel);
}
public ActionResult ServerError()
{
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = (int)HttpStatusCode.InternalServerError;
var viewModel = new ErrorViewModel()
{
ServerException = Server.GetLastError(),
HTTPStatusCode = Response.StatusCode
};
return View(viewModel);
}
}
我在Global.asax.cs中的错误路由:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.MapRoute(
name: "Error - 404",
url: "NotFound",
defaults: …Run Code Online (Sandbox Code Playgroud) 我已成功添加自定义404页面.我想要做的是创建另一个自定义错误页面,当有404以外的任何错误时显示.例如500,403等.
这就是我现在在webconfig中所拥有的
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404.aspx" responseMode="ExecuteURL"/>
</httpErrors>
Run Code Online (Sandbox Code Playgroud) 我使用 IIS7 全新安装了 Windows Server 2008。在那里,我安装了“Classic ASP”并将调试选项“Send Errors To Browser”更改为 True。
1.
我创建了一个包含 2 个文件的目录:
-- C:\inetpub\wwwroot\stadtbibliothek
- index.asp -> <% Response.Write "Hello World" %>
- 500-100.asp -> <% Response.Write "Error" %>
Run Code Online (Sandbox Code Playgroud)
我将目录转换为应用程序并分配了我创建的应用程序池(.net 版本:无托管代码,管道代码:经典)。
然后我从远程客户端 ( http://svr-name.domain/stadtbibliothek/ )测试了页面,“Hello World”出现了。
2.
我向 index.asp 文件和 web.config 文件添加了一个错误到“stadtbibliothek”文件夹(根目录中没有):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="index.asp" />
</files>
</defaultDocument>
<httpErrors>
<remove statusCode="500" subStatusCode="100" />
<error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/error.asp" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
解决方案:
结果我只需要在路径中包含文件夹名称:
<error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/stadtbibliothek/error.asp" responseMode="ExecuteURL" …
我正在尝试在IIS上设置自定义404错误,需要转到ASPX页面(404.aspx).如果我浏览网站并转到一个不存在的.aspx页面(例如/not-here.aspx,则会按预期使用自定义404页面.但是,如果我转到像/ not-here这样的无扩展URL,那么我只是获得IIS自己的默认404页面由静态内容处理程序提供,而不是404.aspx通过ASP.NET
IIS(8.5)设置为"在此站点上执行URL",设置为/404.aspx
如何让IIS使用404.aspx来解决所有404错误?这适用于我们古老的IIS6服务器,但我不能让它在IIS 8.5上工作
我正在尝试在部署在 IBM WebSphere Application Server 8.0.0.8 上的 JSF 应用程序中使用一些错误页面。它们在 中声明如下web.xml:
<error-page>
<error-code>403</error-code>
<location>/error403.jsp</location>
</error-page>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/expired.xhtml</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error500.xhtml</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
但是,它们似乎不起作用。例如,当我ViewExpiredException在重新启动应用程序后得到 a 时,我没有重定向到错误页面,但我SRVE0260E在服务器日志中收到以下错误:
Error Page Exception
SRVE0260E: The server cannot use the error page specified for your application to handle the Original Exception printed below.
Original Exception:
Error Message: javax.servlet.ServletException: /help.xhtmlNo saved view state could be found for the view identifier: /help.xhtml
Error Code: 500
Target Servlet: Faces Servlet
Error Stack:
javax.faces.application.ViewExpiredException: …Run Code Online (Sandbox Code Playgroud) 我正在运行 .NET 3.5 和 IIS7。
我试图使用 customErrors 重定向到一个仍然可以显示异常详细信息、堆栈跟踪等的自定义错误页面。我很难让它工作,尝试了我在网上找到的大约 20 种不同的方法(主要是在 stackoverflow 上),其中一些是其他人的轻微变化。我更喜欢在 Web.config 中进行重定向,因为我希望在代码之外轻松找到/编辑自定义错误页面。
这就是我最终开始工作的内容。我发帖是因为我尝试了很多在这里找到的更复杂的方法,但它们对我不起作用,我只想发布最终成功的简单方法。
网页配置:
<customErrors mode="RemoteOnly" defaultRedirect="~/Error.aspx" redirectMode="ResponseRewrite" />
Run Code Online (Sandbox Code Playgroud)
没有redirectMode="ResponseRewrite",我无法从我的自定义错误页面访问异常详细信息。
错误.aspx
protected void Page_Load(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
if (ex != null)
{
if (ex.GetBaseException() != null) ex = ex.GetBaseException();
litErrorMessage.Text = String.Format("<div class=\"error\">{0}</div>", ex.Message);
litErrorStackTrace.Text = String.Format("<b>Source:</b>\n{0}\n<b>Stack Trace:</b>\n{1}\n", ex.Source, ex.StackTrace);
}
else
{
litErrorStackTrace.Text = "No Exception information available.";
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试使用
HttpException ex = (HttpException)HttpContext.Current.Server.GetLastError();,如某些示例中所见,但这不起作用。
我还尝试了Global.asax -> Application_Error …
我有一个网站使用 cloudflare.com 的免费计划作为反向代理。
\n\n我有一个脚本执行时间超过 60 秒,服务器抛出 504 网关超时,但我没有获得我的 Web 服务器页面,而是获得了 cloudflare 设置的自定义页面,
\n\n我已经仔细检查过,并且我在 cloudflare 中的智能错误应用程序已关闭,那么为什么 cloudflare 仍然提供他们的定制页面?
\n\n我如何关闭 cloudflare 的所有自定义页面并仅用作反向代理。?
\n\n所以我的问题是如何关闭 cloudflare 中的所有自定义错误页面?
\n\n我在 Cent os 7. 64 位上使用 nginx 最新服务器。\n使用最新的 php-fpm。
\n\n更新 :
\n\n这就是我遇到 504 错误时得到的结果。
\n\nError 504 Ray ID: 1fb6a3feef7c17c8 \xe2\x80\xa2 2015-06-24 07:16:17 UTC\nGateway time-out\nYou\nBrowser\nWorking\nSingapore\nCloudFlare\nWorking\nmydomain.com\nHost\nError\nWhat happened?\n\nThe web server reported a gateway time-out error.\nWhat can I do?\n\nPlease try again in a few minutes.\n\nCloudFlare Ray ID: 1fb6a3feef7c17c8 \xe2\x80\xa2 Your IP: myip …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的网站中为“找不到页面”添加自定义404错误页面或输入错误的URL。我有app.yaml文件,并使用过Go语言。我的网站基本上位于Google App Engine中。我检查了每个我认为与我的堆栈溢出问题有关的示例。但是在某些示例中,他们用Python或Java语言解释了示例,但我想用Go语言查找。因为我的代码是用Go编写的。
静态错误404页面已加载到服务器中,但是当我输入错误的URL时,它将显示未找到错误页面而不是我的自定义页面。我已附上截图,它告诉了您一切。
当前:-https : //imgur.com/a/sGrSPyO “这是当前显示的内容”
必需:-https: //imgur.com/a/TxL7NMR “这就是我想要的”
我已经阅读了Google App Engine的app.yaml文档,并尝试放置错误处理程序,但是我没有找到任何解决方案。
app.yaml文件代码
runtime: go
api_version: go1
handlers:
-url: /
static_files: www/index.html
upload: www/index.html
-url: /(.*)
static_files: www/\1
upload: www/(.*)
error_handlers:
-file: www/page-not-found.html*
Run Code Online (Sandbox Code Playgroud)
这是更新的app.yaml文件:
runtime: go
api_version: go1
error_handlers:
- file: /page-not-found.html
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: www/\1
upload: www/(.*)
Run Code Online (Sandbox Code Playgroud) google-app-engine custom-error-pages go vs-web-site-project http-status-code-404
asp.net ×3
c# ×2
iis ×2
asp-classic ×1
axd ×1
cloudflare ×1
exception ×1
go ×1
iis-7 ×1
iis-8 ×1
jsf-2 ×1
php ×1
trace ×1
web-config ×1
websphere ×1