更新时间:2023-08-23 14:30:16
使用Application_Error
事件.
参见此处: http://msdn.microsoft.com/en-us/library/24395wz3.aspx [^ ]
对于Web服务,请参见此处:用户友好的ASP.NET异常处理 [
Use theApplication_Error
event.
See here : http://msdn.microsoft.com/en-us/library/24395wz3.aspx[^]
For Web Services see here : User Friendly ASP.NET Exception Handling[^]
public class ServiceHostGeneralErrorHandler : IErrorHandler
{
public void ProvideFault(Exception ex, MessageVersion version, ref Message fault)
{
if (ex is FaultException)
return;
// a general message to the client
var faultException = new FaultException("A General Error Occured");
MessageFault messageFault = faultException.CreateMessageFault();
fault = Message.CreateMessage(version, messageFault, null);
}
public bool HandleError(Exception ex)
{
// log the exception
// mark as handled
return true;
}
}
如果解决了您的问题,请标记为解决方案.
Please mark as solution if it solved your problem.