我在带有 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
为空。另一方面,邮政使用 Razor 来呈现电子邮件,因此会触发 Glimpse 拦截器。
是否有可能禁用此特定代码块的 Glimpse?
实现自定义IRuntimePolicy
似乎不是一种可能性,因为在这种情况下不会调用它。此问题中提供的解决方法也不是,因为System.Web.HttpContext.Current
在 SharePoint 远程事件接收器中为 null。我还尝试使用以下代码将远程事件接收器的 URL 列入黑名单,但 Glimpse 似乎仍然被调用(远程事件接收器位于名为 Services 的目录中):
<runtimePolicies>
<uris>
<add regex=".*\/Services\/.*"/>
</uris>
</runtimePolicies>
随着defaultRuntimePolicy="Off"
代码的工作。