禁用某个代码块的Glimpse

时间:2016-05-24 09:22:26

标签: c# asp.net sharepoint glimpse postal

我在使用ASP.NET MVC应用程序的SharePoint提供程序托管加载项中使用Glimpse(1.8.6)。在一个地方,我们使用SharePoint远程事件接收器,这是从SharePoint到我们的ASP.NET 5应用程序的调用,我们使用Postal来呈现和发送电子邮件。

这导致以下NullReference例外:

at Glimpse.AspNet.AspNetFrameworkProvider.get_HttpRequestStore()
at Glimpse.Core.Framework.Factory.<>c__DisplayClass5.<InstantiateRuntimePolicyStrategy>b__4()
at Glimpse.Core.Extensions.AlternateMethodContextExtensions.TryProceedWithTimer(IAlternateMethodContext context, TimerResult& timerResult)
at Glimpse.Core.Extensibility.AlternateMethod.NewImplementation(IAlternateMethodContext context)
at Glimpse.Core.Extensibility.AlternateTypeToCastleInterceptorAdapter.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.IDependencyResolverProxy.GetServices(Type serviceType)
at System.Web.Mvc.DependencyResolverExtensions.GetServices[TService](IDependencyResolver resolver)
at System.Web.Mvc.MultiServiceResolver.GetCombined[TService](IList`1 items, IDependencyResolver resolver)
at System.Web.Mvc.ViewEngineCollection.get_CombinedItems()
at System.Web.Mvc.ViewEngineCollection.Find(Func`2 lookup, Boolean trackSearchedPaths)
at System.Web.Mvc.ViewEngineCollection.Find(Func`2 cacheLocator, Func`2 locator)
at System.Web.Mvc.ViewEngineCollection.FindView(ControllerContext controllerContext, String viewName, String masterName)
at Postal.EmailViewRenderer.CreateView(String viewName, ControllerContext controllerContext)
at Postal.EmailViewRenderer.Render(Email email, String viewName)
at Postal.EmailService.CreateMailMessage(Email email)
at Postal.EmailService.Send(Email email)
at CallSite.Target(Closure , CallSite , EmailService , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
at MyWebApp.Services.MyRemoteEventReceiver.DoSomething(SPRemoteEventProperties properties) in d:\Repos\MyRemoteEventReceiver.svc.cs:line 331
at SyncInvokeProcessEvent(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

由于此请求不是从用户浏览器的调用触发,而是从SharePoint触发到ASP.NET应用程序System.Web.HttpContext.Current为空。 另一方面,Postal使用Razor渲染电子邮件,因此触发了Glimpse拦截器。

是否有可能禁用此特定代码块的Glimpse?

实现自定义IRuntimePolicy似乎不太可能,因为在这种情况下不会调用它。 由于System.Web.HttpContext.Current在SharePoint远程事件接收器中为空,因此this question中提供的解决方法也不是。 我还尝试使用以下代码将远程事件接收器的URL列入黑名单,但似乎仍然调用Glimpse(远程事件接收器位于名为Services的目录中):

<runtimePolicies>
  <uris>
    <add regex=".*\/Services\/.*"/>
  </uris>
</runtimePolicies>

使用defaultRuntimePolicy="Off"代码可以正常工作。

1 个答案:

答案 0 :(得分:1)

正则表达式运行时策略只是阻止Glimpse存储收集的数据,但正如您从调用堆栈中看到的那样,它不会阻止拦截器观察请求。

您可以通过将其添加到配置的<glimpse>节点来禁用它:

<inspectors>
    <ignoredTypes>
        <add type="Glimpse.Mvc.Inspector.ViewEngineInspector, Glimpse.Mvc3" />
    </ignoredTypes>
</inspectors>