|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionSpeeding up SharePoint Portal Server webparts are relative easy if you understand the asynchronous data retrieval built into the webpart framework. Just one problem, the second asynchronous thread runs under the system account's permissions. This article is not on how to get asynchronous data retrieval working (even though the code is included), but rather on how to get the current logged on users credentials to be used while running the second asynchronous thread. BackgroundWhile recently developing a treeview navigation webpart I had the opportunity to get my hands dirty with the asynchronous data retrieval functionality built into the webpart framework. It was easy enough to get to work. The only problem that I found was that when I wanted to determine (during he asynchronous routine) whether the logged on user had permissions to view an area, it would always return true. Some assumptions
Using the codeYou have to return true for the Public Overrides Function GetRequiresData() As Boolean
Return True
End Function
As you have indicated that you want to use asynchronous data retrieval, the framework will next check the Public Overrides Sub GetData()
RegisterWorkItemCallback(New Threading.WaitCallback(AddressOf ImpersonatedCallbackMethod), Nothing)
End If
Now that the asynchronous data retrieval is ready, you have to get the callback method configured so that the current logged on user is impersonated. Private Sub ImpersonatedCallbackMethod(ByVal usr As Object)Impersonate the current logged on user. Dim impersonationContext As System.Security.Principal.WindowsImpersonationContext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
currentWindowsIdentity = CType(System.Security.Principal.WindowsIdentity.GetCurrent, _
System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate() Run any script that needs to use the permissions of the current user and finally remove the impersonation. 'Remove the impersonation
impersonationContext.Undo()
End Sub
Points of InterestThe asynchronous thread will time out after the default 7 seconds and is controlled by the
|
||||||||||||||||||||||