by

Workaround for Aptimize bug and list access denied in SharePoint

Update: It looks like this was a false positive. Yes, all the errors could be replicated by switching the Aptimize on and off but I could not reproduce this issue in a brand new environment which means, Aptimize might not be the problem here but other environmental issues.
As soon as I have more news/fix/info about it I will update this post. Thanks to all the Aptimize people for the contact and great support on this case.


If you are using a product called Aptimize for SharePoint you might have noticed that it is a great product when it comes to minimizing the footprint in the front end and reducing the rendered size of the output. Unfortunately with great power comes also some inconvenient bugs. Like the one below.
In our test scenario we will have a normal SharePoint document library...
aptimize-bug-sharepoint-2007-1
...with versioning, content approval and major and minor versions enabled.
aptimize-bug-sharepoint-2007-2
...Nothing unusual here. Very well.
Then we will have a custom SharePoint page with a custom webpart in it that does a simple thing: loop through the specified library and builds up a list of those items who are published or have a published version.
1 private static void LoadFake(SPSite site, string virtualLibraryPath, IDictionary<string, bool> fake)
2 {
3 using (SPWeb web = site.OpenWeb(virtualLibraryPath))
4 {
5 SPList list = web.GetList(virtualLibraryPath);
6 SPListItemCollection items = list.Items;
7 foreach (SPListItem item in items)
8 {
9 if(item.HasPublishedVersion)
10 {
11 // do anything here...
12 }
13 }
14 }
15 }
The code above works EXCEPT if you have at least one item in that library in pending approval state AND you have APTIMIZE installed in the server; then you will see that SharePoint error.
aptimize-bug-sharepoint-2007-access-denied
error: access denied - current user - you are currently signed in as: xxx - sign in as a different user
If you go to the event viewer you will notice that Aptimize might be running with no problems at all.
aptimize-bug-sharepoint-2007-event-viewer-3
Aptimize Website Accelerator initialized successfully.
Settings:
Enabled: True
RunMode: Development
AutoVersionUrls: True
UseAlternateAutoVersionUrlFormat: False
NewInstall: True
UseDefaultSystemProxy: False
MaxOptimizationsPerSecond: 50
CacheMaxMemory: 100
ResourceSetCacheMaxAge: 172800
PageSpriteCacheMaxAge: 28800
CachePath:
HandlerName: wax.axd
RunAsDaemon: False
VirtualRoot:
DefaultCharset:
PreviewMode: False
IncludeOriginalImageUrl: False
InlineCssImagesOnVista: True
ForceGzipOn: False
ForwardClientAddress: False
TrustedForwarders:
PageCachingEnabled: False
PageCachingVaryBy: Cookie
PageCachingVaryByParam:
IncludeFromDomains: ThisDomain
DiskCacheCleanupInterval: 60
MemoryCacheCleanupInterval: 1
ResourceClientCacheDuration: 259200
ResourceRecheckInterval: 60
PageClientCacheDuration: 30
PageRecheckInterval: 10
Action: Exclude
CombineStyleSheets: All
CombineImages: All
HttpCompression: Smallest
CombineBodyScripts: All
CombineHeadScripts: All
InlineCssImages: True
MaxInlineImageSize: 1200
BodyScriptInsertionPoint: BodyStart
HeadScriptInsertionPoint: BodyStart
AsyncScriptLoading: False
AsyncStyleSheetLoading: False
LogInfoLevel: Info
ProxyCacheable: False
ShrinkCss: True
ShrinkScripts: True
ShrinkImages: True
JpegQuality: 85
ConvertGifToPng: False
HttpFetchTimeout: 5000
EnableClientApi: False
SuppressedErrorCodes:
CacheableMimeTypes: text/css,text/javascript,application/x-javascript,image/gif,image/png,image/jpeg,image/jpg,image/bmp,image/x-icon,application/x-shockwave-flash
CompressableMimeTypes: text/html,application/xhtml+xml,text/css,text/javascript,application/x-javascript,text/xml,application/xml,application/json

But then a lit bit later you will see these two entries in the event log
aptimize-bug-sharepoint-event-viewer-1
Error initializing Safe control - Assembly:Mondosoft.Ontolica.SharePoint.Reporting, Version=3.0.0.0, Culture=neutral, PublicKeyToken=c7127db7656685c6 TypeName: Mondosoft.Ontolica.SharePoint.Reporting.WebControls.WebParts.ReportingWebPart Error: Could not load file or assembly 'Microsoft.ReportingServices.SharePoint.UI.WebParts, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp
aptimize-bug-sharepoint-2007-event-viewer-2
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://xx.xx.xx.xx, which has not been configured in Alternate Access Mappings. Some links may point to the Alternate Access URL for the default zone, http://www.www.ww. Review the Alternate Access mappings for this Web application at http://myserver:9100/_admin/AlternateUrlCollections.aspx and consider adding http://xxx.xxx.xxx.xx as a Public Alternate Access URL if it will be used frequently. Help on this error: http://go.microsoft.com/fwlink/?LinkId=114854
If you now go to the Aptimize console and turn off the website optimization, the error goes away.
The curious thing. if you debug that code above you will noticed that an exception will happen at line #9.
Apparently Aptimize is doing something under the hood that causes a privilege exception when calling SPListItem.HasPublishedVersion even if you are running as System Administrator and even if you are running using RunWithElevatedPrivileges method. Inspect the returned error and it will see an UnauthorizedAccessException.
The fix for now is to avoid calling HasPublishedVersion until we hear back from the Aptimize guys.
If someone out there seen the same issue and would like to share any ideas, feel free. Meanwhile I hope this workaround helps someone.
See you later

By