开发者

SPContext.Current throws SecurityException for most properties

Many properties for SPContext.Current objects throws SecurityException. (Like SPContext.Current.Fields, many properties in SPContext.Current.Site (see details).

  • DLL Is in GAC
  • Using Site Owner when trying those properties.
  • Maybe it has to do something with database access? However SharePoint site is working - I can add list items, etc.
  • Application Pool has permissions to database. Should I set application pool account as farm admin or it is not necessary?
  • In my Development environment, it just works.

Where could be the problem? Could someone, please, point me in right direction?

Thank you.

Details

From Immediate window:

SPContext.Current.Site
{Microsoft.SharePoint.SPSite}
    AllowRssFeeds: true
    AllowUnsafeUpdates: 'SPContext.Current.Site.AllowUnsafeUpdates' threw an exception of type 'System.Security.S开发者_开发技巧ecurityException'
    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'
    ...

And even exception have exception's within himself:

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

ULS Log somwhere in that time, when exception occurs: ULS Log http://img715.imageshack.us/img715/465/ss20100204113046.png

Event Viewer has bunch of errors

  • for SharePoint search Indexer (i don't have a working search at the moment, I just hope it is not the problem)
  • And there is an error about Alternate Access Mapping (Sometimes I access SharePoint from IP address, not from hostname, as hostnames do not resolve in VPN for me, but that's a different problem):

    The description for Event ID ( 8214 ) in Source ( Windows SharePoint Services 3 ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: A request was made for a URL, http://192.168.0.9, which has not been configured in Alternate Access Mappings. Some links may point to the Alternate Access URL for the default zone, http://serveris. Review the Alternate Access mappings for this Web application at http://serveris:38590/_admin/AlternateUrlCollections.aspx and consider adding http://192.168.0.9 as a Public Alternate Access URL if it will be used frequently. Help on this error: http://go.microsoft.com/fwlink/?LinkId=114854.


I know I have had to use code to ensure that the SPContext exists when executing from a non-web context.

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;

    }


Ahh, the issue is now resolved after stepping already like 3rd time on the same rake.

It was happening in WebPart constructor (do not know if it plays a role, but inherited from Microsoft.SharePoint.WebPartPages.WebPart) and there the SPContext object was messed up.

Interesting that it works in my development environment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜