实际上这是一个两部分的问题。第一,HttpContext.Current是否对应于当前的System.UI.Page对象?
而第二个问题,可能与第一个问题有关,为什么我不能使用以下代码来查看当前页面是否实现了一个接口:
private IWebBase FindWebBase()
{
if (HttpContext.Current as IWebBase != null)
{
return (IWebBase)HttpContext.Current.;
}
throw new NotImplementedException("Crawling for IWebBase not implemented yet");
}
通常情况下,一些控件需要知道它们是在SharePoint WebPart中执行还是作为Asp.Net框架的一部分执行。
我通过要求控件传递对自身的引用并检查控件的Page属性来解决了此问题,但我仍然很好奇为什么上述方法不可行。
编译器错误是: Cannot convert System.Web.HttpContext to ...IWebBase via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion or null type conversion。