我正在寻找第一次使用ELMAH,但是需要满足我不确定如何实现的要求......
基本上,我将配置ELMAH在asp.net MVC下工作,并让它在发生错误时将错误记录到数据库中.除此之外,我将使用customErrors在发生错误时将用户定向到友好的消息页面.相当标准的东西......
要求是在这个自定义错误页面上我有一个表单,使用户可以根据需要提供额外的信息.现在问题出现的原因是此时已经记录了错误,我需要将漏洞错误与用户反馈相关联.
通常,如果我使用自己的自定义实现,在记录错误后,我会将错误的ID传递给自定义错误页面,以便可以建立关联.但由于ELMAH的工作方式,我不认为这是可能的.
因此我想知道人们怎么会想到这样做......
干杯
更新:
我对这个问题的解决方案如下:
public class UserCurrentConextUsingWebContext : IUserCurrentConext
{
private const string _StoredExceptionName = "System.StoredException.";
private const string _StoredExceptionIdName = "System.StoredExceptionId.";
public virtual string UniqueAddress
{
get { return HttpContext.Current.Request.UserHostAddress; }
}
public Exception StoredException
{
get { return HttpContext.Current.Application[_StoredExceptionName + this.UniqueAddress] as Exception; }
set { HttpContext.Current.Application[_StoredExceptionName + this.UniqueAddress] = value; }
}
public string StoredExceptionId
{
get { return HttpContext.Current.Application[_StoredExceptionIdName + this.UniqueAddress] as string; }
set { HttpContext.Current.Application[_StoredExceptionIdName + this.UniqueAddress] = value; …Run Code Online (Sandbox Code Playgroud) 我试图在发生403错误时在/temp/www/error403.html中显示错误页面.
这应该是每当用户尝试通过https(ssl)访问该站点并且它的IP位于blovkips.conf文件中时,但此时它仍然显示nginx的默认错误页面.我有其他服务器相同的代码(没有任何阻止),它的工作原理.
是否阻止IP访问自定义403页面?如果是这样,我如何让它工作?
server {
# ssl
listen 443;
ssl on;
ssl_certificate /etc/nginx/ssl/site.in.crt;
ssl_certificate_key /etc/nginx/ssl/site.in.key;
keepalive_timeout 70;
server_name localhost;
location / {
root /temp/www;
index index.html index.htm;
}
# redirect server error pages to the static page
error_page 403 /error403.html;
# location = /error403.html {
# root /temp/www;
# }
# add trailing slash if missing
if (-f $document_root/$host$uri) {
rewrite ^(.*[^/])$ $1/ permanent;
}
# list of IPs to block
include blockips.conf;
}
Run Code Online (Sandbox Code Playgroud)
编辑: 更正了错误页面代码从504到403,但我仍然有同样的问题
我正在使用Tomcat 7和JSP页面.我想为HTTP 500错误提供自定义错误页面.
我所做的是声明自定义错误页面如下web.xml:
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
我创建了一个error.jsp使用以下代码调用的JSP :
<%@ page pageEncoding="UTF-8" isErrorPage="true" %>
<!DOCTYPE html>
<html>
<head>
<title>500</title>
</head>
<body>
<img src="${pageContext.request.contextPath}/images/500.jpg" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
现在这适用于大多数浏览器,但在Internet Explorer中我被带到标准"网站无法显示页面"页面.
为什么我的自定义HTTP 500错误页面未在Internet Explorer中显示?
我有这个配置工作,并正确重定向以下错误
<httpErrors errorMode="Custom"
existingResponse="Replace"
defaultResponseMode="ExecuteURL" >
<remove statusCode="403" />
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="403" responseMode="ExecuteURL" path="/Error/AccessDenied" />
<error statusCode="404" responseMode="ExecuteURL" path="/Error/PageNotFound" />
<error statusCode="500" responseMode="ExecuteURL" path="/Error/ApplicationError" />
</httpErrors>
Run Code Online (Sandbox Code Playgroud)
但是当我添加以下默认路径以尝试添加catch all时
<httpErrors errorMode="Custom"
existingResponse="Replace"
defaultResponseMode="ExecuteURL"
defaultPath="/Error/ApplicationError">
Run Code Online (Sandbox Code Playgroud)
服务器抛出web.config错误
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Module CustomErrorModule
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!!
我创建了一个使用集成Windows身份验证的ASP.NET MVC应用程序.实施了以下授权逻辑:
尝试通过NTLM从活动目录获取帐户凭据.
显示Windows身份验证对话框,以便用户可以提供其他凭据:

然后我使用VictorySaber的解决方案为应用程序添加了自定义错误页面:
protected void Application_EndRequest()
{
int status = Response.StatusCode;
string actionName;
if (status >= 400 && status < 500)
{
switch (status)
{
case 401:
actionName = "Unauthorized";
break;
// Handle another client errors
default:
actionName = "BadRequest";
break;
}
}
else if (status >= 500 && status < 600)
{
switch (status)
{
case 501:
actionName = "NotImplemented";
break;
// Handle another server errors
default:
actionName = "InternalServerError"; …Run Code Online (Sandbox Code Playgroud) 对于我的网站,我配置了一些自定义错误页面 如果我生成404,重定向工作正常.点击400时,显示"错误请求"文本而不是配置的URl.
作为测试,我将URL从404复制到400.没有变化.然后我将重定向更改为文件.没变.
有任何想法吗?
我的设置:Apache 2.2 + Tomcat 6.0 @ Windows 2008 R2 64bit
tomcat的\的conf\web.xml文件:
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
阿帕奇\的conf \额外\的httpd-ssl.conf中:
JkMount /foo/* worker1
JkMount /404.jsp worker1
Run Code Online (Sandbox Code Playgroud)
当我打开https://...../404.jsp时,会显示我的自定义错误页面.但是当我打开https://...../foo/nonexisting.html时,会显示一个空白页面.
如果我<error-page>...</error-page>从web.xml中删除代码并打开https://...../foo/nonexisting.html,则显示tomcats自己的404.
任何提示?
是否有可能在全球范围内捕获Classic ASP中的所有500个错误?也许是IIS中的东西.我现在正在使用II6.我喜欢捕获错误消息,然后将其存储在数据库中.我知道它可能在ASPX页面中,但不知道你在经典asp中的确切方式.
谢谢
我试图在Symfony中自定义错误页面.
这是我的error.html.twig文件位于app/Resources/TwigBundle/views/Exception/:
{% extends '::base.html.twig' %}
{% block body %}
<h1>{{ status_code }}: {{ status_text }}</h1>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
不幸的是我收到以下错误消息:
致命错误:第144行上的供应商\ symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php中未捕获的异常'Symfony\Component\Routing\Exception\ResourceNotFoundException'
当我删除{% extends '::base.html.twig' %}一切工作正常.有关如何将我的基本模板包含在错误页面中的任何想法?
编辑1:
奇怪的是它似乎在抛出403时工作,例如,当我访问/user但没有必要的权限时.
编辑2:
我将我的整个内容粘贴base.html.twig到error.html.twig文件中,并注意到错误是由于KnpMenuBundle捆绑包呈现的菜单引起的:
{{ knp_menu_render('ACMEMemberBundle:Builder:mainMenu', { 'style': 'pills', 'currentClass': 'active' }) }}
Run Code Online (Sandbox Code Playgroud)
当我删除这一行时,一切正常.但这不是我想要的方式.导航没有可能吗?
我正在使用asp.net MVC4 + visual studio 2012.一切都很好,但只有自定义错误总是在URL上有aspxerrorpath参数.
我已经在web.config上配置了自定义错误:
<customErrors mode="On" defaultRedirect="~/Error/Error">
<error redirect="~/Error/Error" statusCode="404" />
<error redirect="~/Error/Error" statusCode="500" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)
我还将错误操作更改为:
public ActionResult Error()
{
Response.Status = "404 Not Found";
Response.StatusCode = 404;
return View();
}
Run Code Online (Sandbox Code Playgroud)
现在会发生404事件.我的URL上总是有aspxerrorpath param.
我尝试添加redirectMode="ResponseRewrite"到customError节点但是如果添加这个,错误将显示运行时异常.....
那么有没有最好的方法来删除aspxerrorpath param?谢谢.
asp.net ×2
asp.net-mvc ×2
asp-classic ×1
c# ×1
elmah ×1
iis ×1
iis-7 ×1
jsp ×1
nginx ×1
symfony ×1
tomcat ×1
web-config ×1
webserver ×1