SimpleWorkerRequest request = new SimpleWorkerRequest(
"/blah", @"c:\inetpub\wwwroot\blah", "blah.html", null, new StringWriter());
HttpContext.Current= new HttpContext(request);
有了这个,它就不应该再抛出异常了,因为
httpContext.current当前
不是空的。
围绕要引发的调用创建一个包装类,并模拟包装类。
public class ErrorSignaler {
public virtual void SignalFromCurrentContext(Exception e) {
if (HttpContext.Current != null)
Elmah.ErrorSignal.FromCurrentContext().Raise(e);
}
}