0
votes

I want to prevent the user from accessing some lists directly but i want him to be able to access these lists using my webpart only. My web part contains some XsltListViewWebPart controls that are bound to those lists.

Now i'm preventing the user from direct-accessing those lists using the list permissions. but i need him to be able to access those lists using the XsltListViewWebPart in my webpart. So i want now to run my webpart with elevated privileges to allow the user to access those lists.

How to do this ?

2

2 Answers

0
votes

You can use this site: Run With Elevated Privileges

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    //New SPSite object.
     using (SPSite site = new SPSite(web.Site.ID))
     {
    //Do things by assuming the permission of the "system account".
     }
});
0
votes

You can provide users required permissions to the list and restrict the list views by using the property "Target Audiences".This way XSLTListViewWebpart will not be restricted and direct access to list will also be restricted