代码之家  ›  专栏  ›  技术社区  ›  Janis Veinbergs

spContext.current引发大多数属性的SecurityException

  •  0
  • Janis Veinbergs  · 技术社区  · 15 年前

    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日志somwhere: ULS Log http://img715.imageshack.us/img715/465/ss20100204113046.png

    事件查看器有许多错误

    • 对于SharePoint搜索索引器(i 没有工作搜索 现在,我只是希望不是 问题)
    • 还有一个关于备用的错误 访问映射(有时我访问 来自IP地址的SharePoint,而不是来自 主机名,因为主机名无法解析 对我来说,在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 .

    2 回复  |  直到 13 年前
        1
  •  1
  •   Mandrake    13 年前

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

    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
  •  0
  •   Janis Veinbergs    15 年前

    啊,这个问题已经解决了,就像第三次踩在同一个耙子上一样。

    它发生在Web部件构造函数中(不知道它是否扮演角色,但继承自 Microsoft.SharePoint.WebPartPages.WebPart )在那里,spContext对象被弄乱了。

    有趣的是它在我的开发环境中工作。