ASP.NET Health Monitoring 404 Event

≯℡__Kan透↙ 提交于 2019-12-10 11:09:36

问题


Does HealthMonitoring have a built-in event that catches 404 errors? I have tried setting up all events (by using webBaseEvent) and I've searched for two days, but I cannot find or trigger an event for a file not found.

I could create my own, but was hoping there was a built in event.


回答1:


No, it doesn't. You'd have to create a custom event (from webrequesterrorevent) to have HM track it for you.

How to: Something like this (from memory) in Application_Error in global.asax -

public void Application_Error()
{
    var exception = Server.GetLastError() as HttpException;
    if (exception != null && exception.GetHttpCode() == 404)
    {
       //custom error
       new Http404Event(this, exception).Raise();
    }
}


来源:https://stackoverflow.com/questions/4957566/asp-net-health-monitoring-404-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!