【问题标题】:SPContext.Current throws SecurityException for most propertiesSPContext.Current 为大多数属性抛出 SecurityException
【发布时间】:2011-08-12 04:58:28
【问题描述】:

SPContext.Current 对象的许多属性引发 SecurityException。 (和 SPContext.Current.Fields 一样,SPContext.Current.Site 中有很多属性(见详情)。

  • DLL 在 GAC 中
  • 在尝试这些时使用站点所有者 属性。
  • 也许它与 数据库访问?然而 SharePoint 网站正在运行 - 我可以添加列表 物品等。
  • 应用程序池有权限 数据库。我应该设置应用程序 池帐户作为场管理员,或者它是 没必要?
  • 在我的开发环境中,它 刚刚好。

问题可能出在哪里?有人可以指出我正确的方向吗?

谢谢。

详情

从即时窗口:

SPContext.Current.Site
{Microsoft.SharePoint.SPSite}
    AllowRssFeeds: true
    AllowUnsafeUpdates: 'SPContext.Current.Site.AllowUnsafeUpdates' threw an exception of type 'System.Security.SecurityException'
    AllWebs: {Microsoft.SharePoint.SPWebCollection}
    ApplicationRightsMask: 9223372036854775807
    Audit: {Microsoft.SharePoint.SPAudit}
    CatchAccessDeniedException: true
    CertificationDate: 'SPContext.Current.Site.CertificationDate' threw an exception of type 'System.Security.SecurityException'
    ContentDatabase: {Microsoft.SharePoint.Administration.SPContentDatabase}
    CurrentChangeToken: 'SPContext.Current.Site.CurrentChangeToken' threw an exception of type 'System.Security.SecurityException'
    ...

即使是例外,自己也有例外:

Exception Window http://img41.imageshack.us/img41/442/ss20100204112542.png

发生异常时,ULS 在某个时间记录某处: ULS Log http://img715.imageshack.us/img715/465/ss20100204113046.png

事件查看器有一堆错误

  • 用于 SharePoint 搜索索引器(i 没有有效的搜索 那一刻,我只希望它不是 问题)
  • 还有关于 Alternate 的错误 访问映射(有时我访问 SharePoint 来自 IP 地址,而不是来自 主机名,因为主机名无法解析 对我来说在 VPN 中,但那是不同的 问题):

    在源 (Windows SharePoint Services 3) 中找不到事件 ID (8214) 的描述。这 本地计算机可能没有 必要的注册信息或 用于显示消息的消息 DLL 文件 从远程计算机。你可能会 能够使用 /AUXSOURCE= 标志来 检索此描述;见帮助 并支持详细信息。这 以下信息是其中的一部分 事件:对 URL 进行了请求, http://192.168.0.9,没有 已在备用访问中配置 映射。一些链接可能指向 的备用访问 URL 默认区域,http://serveris。 查看备用访问映射 此 Web 应用程序位于 http://serveris:38590/_admin/AlternateUrlCollections.aspx 并考虑添加 http://192.168.0.9 作为公众 备用访问 URL(如果是) 经常使用。帮助解决此错误: http://go.microsoft.com/fwlink/?LinkId=114854.

【问题讨论】:

    标签: sharepoint exception


    【解决方案1】:

    我知道我必须使用代码来确保从非 Web 上下文执行时 SPContext 存在。

    public static void EnsureSPContext(this SPWeb web)
        {
            // Ensure HttpContext.Current
            if (HttpContext.Current == null)
            {
                HttpRequest request = new HttpRequest("", web.Url, "");
                HttpContext.Current = new HttpContext(request,
                  new HttpResponse(TextWriter.Null));
            }
    
            // SPContext is based on SPControl.GetContextWeb(), which looks here
            if (HttpContext.Current.Items["HttpHandlerSPWeb"] == null)
                HttpContext.Current.Items["HttpHandlerSPWeb"] = web;
    
        }
    

    【讨论】:

      【解决方案2】:

      啊,在同一个耙子上第三次踩踏之后,问题现在已经解决了。

      它发生在 WebPart 构造函数中(不知道它是否起作用,但继承自 Microsoft.SharePoint.WebPartPages.WebPart)并且 SPContext 对象被搞砸了。

      有趣的是,它可以在我的开发环境中使用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-07
        • 2016-11-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多