ASP.NET Health Monitoring 404 Event

2019-05-22 02:15发布

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条回答
够拽才男人
2楼-- · 2019-05-22 02:35

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();
    }
}
查看更多
登录 后发表回答