- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在我的 MVC 网络项目中。我试图在不使用 web.config 中的“custromerrors”元素的情况下向访问者显示自定义错误页面。
我可以捕获如下异常
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
bool success = RaiseErrorSignal(exception);
Response.Clear();
HttpException httpException = exception as HttpException;
RouteData routeData = new RouteData();
routeData.Values.Add("controller", "Error");
if (httpException == null)
{
routeData.Values.Add("action", "Index");
}
else //It's an Http Exception, Let's handle it.
{
switch (httpException.GetHttpCode())
{
case 404:
// Page not found.
routeData.Values.Add("action", "Error404");
break;
case 500:
// Server error.
routeData.Values.Add("action", "Error500");
break;
// Here you can handle Views to other error codes.
// I choose a General error template
default:
routeData.Values.Add("action", "Index");
break;
}
}
// Pass exception details to the target error View.
routeData.Values.Add("error", exception);
// Clear the error on server.
Server.ClearError();
// Call target Controller and pass the routeData.
IController errorController = new ProjectName.WebSite.Controllers.ErrorController();
errorController.Execute(new RequestContext(
new HttpContextWrapper(Context), routeData));
}
private static bool RaiseErrorSignal(Exception e)
{
var context = HttpContext.Current;
if (context == null)
return false;
var signal = ErrorSignal.FromContext(context);
if (signal == null)
return false;
signal.Raise(e, context);
return true;
}
但 Elmah 无法记录错误,我也在发出错误信号。
最佳答案
我发现了问题,我漏掉了一个 web.config 部分。我将“ErrorLog”模块添加到 <system.webserver><modules>
.
我还需要将它添加到 <system.web><httpModules>
.
添加后,Elmah 开始记录错误。
另外我不需要调用 ErrorSignal.Raise() 方法,Elmah 可以在没有信号的情况下检测到错误。
关于c# - Elmah 不记录异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4615755/
有人成功使用过 CaSTLe MonoRail 和 ELMAH 吗? 我们正在使用许多 Resuces 向用户显示友好的错误消息,但如果我们这样做,异常永远不会像 MonoRail 救援拦截它们那样达
我正在尝试配置 ELMAH 以发送电子邮件,但出现以下错误: Server Error in '/' Application. The SMTP server requires a secure co
在我的作品中,我们制作的网站好像已经过时了(即每年有很多网站) 我想在所有这些上安装 ELMAH 作为公司实践,然后集中记录所有内容以供我们的开发人员查看。这个过程必须非常简单,否则它的使用不会起飞。
任何人都可以建议一种快速的方法来告诉 Elmah 不要将电子邮件处理程序用于本地请求吗? 即当 Request.IsLocal == true我不想每次生成异常时都收到电子邮件。或者,一种简单地为本地
我想在我的 web.config 中以声明方式过滤 ELMAH 结果。我无法成功过滤掉我想要的一些异常。 HttpStatusCode 已成功过滤,但我仍无法通过 ViewStateException
安装后elmah.mvc来自 nuget: 默认创建的日志文件在哪里? 当我转到 时,错误记录得很好/myapp/elmah 但是我没有看到实际的日志文件所在的位置。 谢谢 最佳答案 查看 myapp
设置: 我通过 NuGet 在 ASP.NET MVC 4 站点上安装了 ELMAH。 在开发计算机上,应用程序安装在根目录下。一切正常,并且样式与 ELMAH 页面通常一样。它总是这样做,我的意思是
我的雇主目前正在试用 Fogbugz,其中一个不错的功能是我们的异常记录器 (ELMAH) 和 FogBugz 中的案例生成之间的某种自动化。具体来说,如果有一个模块可以向 FogBugz 发送错误报
我发布了我的网站并抛出了异常,但 App_Data 文件夹中没有生成错误文件。我想知道它是否具有对该文件夹的写访问权限。 文档说 ASP.Net 进程需要写访问权限,但不确定这是什么意思。有人能告诉我
我在独立(非 Azure)项目中使用了 ELMAH。对于 Azure 相关项目,我遇到了 Windows Azure 诊断 (WAD) 库。 从表面上看,它们似乎做同样的事情(Azure Diagno
我已通过 Nuget 将 Elmah.mvc 集成到我的 mvc 应用程序中。它正确存储日志,但是当我在 web.config 中进行任何更改或重新启动站点时,所有存储的错误日志都会被删除。有没有办法
该应用程序包括: ASP .NET MVC Web 应用程序 达尔 后台服务 图书馆项目 Web 应用程序和后台服务项目使用库项目来发送电子邮件。 SMTP 设置包含在库项目本身的配置文件中。 在这种
我在我的 ASP.NET 项目中使用 ELMAH 进行错误报告。一切正常,除了在调试项目时,我不想向允许的用户发送电子邮件报告。 我怎样才能完成这个壮举? 最佳答案 假设您的开发和生产环境有不同的 w
我目前正在使用 NLog 从我的 ASP.NET MVC3 应用程序中记录安全事件。 现在我们有另一个要求将应用程序错误添加到单独的日志中。 由于我们已经在使用 NLog(并且喜欢 Targets 的
我安装了 elmah.mvc nuget 包并保留了默认配置,没有设置发送电子邮件并将其插入 SQL 数据库。 当我使用 Visual Studio 主机时,在我的本地计算机上,我可以打开我的应用程序
我基本上已经加载了 Elmah 程序集并使用 NuGet 插件安装了该包。我记得它与我的一个项目一起工作,但突然它停止与 “无法从程序集 'Elmah' 加载类型 'Elmah.ErrorLogMod
我在/elmah.axd 路径上看不到未处理的异常 (MyService:RestServiceBase)。 我添加了用于查看错误的 http 处理程序。 我已经安装了 ServiceStack.
我有Code First MVC 4应用程序。 我尝试安装用于记录Elmah的NuGet软件包-似乎一切正常-错误消息在http://myapp/elmah.axd 然后我注意到有一个Elmah.MV
任何人都可以帮助我了解如何使用 ELMAH 和 C# 记录自定义消息,以防万一成功的 Web 请求返回状态代码 200。 有没有类似于下面提到的方法: Elmah.ErrorSignal.FromCu
我是 ASP.NET MVC 的新手,我正在寻找最不痛苦的方法来设置全局错误处理、日志记录和报告(通过电子邮件)。仅供引用,我的 ASP.NET MVC 应用程序在 Azure 中作为 Web 角色托
我是一名优秀的程序员,十分优秀!