Reputation: 6988
Many properties for SPContext.Current objects throws SecurityException. (Like SPContext.Current.Fields, many properties in SPContext.Current.Site (see details).
Where could be the problem? Could someone, please, point me in right direction?
Thank you.
From Immediate window:
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'
...
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
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.
Upvotes: 0
Views: 1244
Reputation: 1161
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;
}
Upvotes: 1
Reputation: 6988
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.
Upvotes: 0