There is a way how we can secure the object in WSS. When I say secure it means objects exposes several methods which will allow us to determine the rights or the permission related stuff on list / document library level, item level and individual site level.
Here we are talking about understanding DoesUserHavePermissions method on these securable objects.
Let us take an example one by one. First we will talk about permission checking on site level.
Let’s say we have taken the reference of current site and it is stored in objWeb, then this method checks if the current user has permission to View the List Items?
if(objWeb.DoesUserHavePermissions(SPBasePermissions.ViewListItems))
{
// your code goes here
}
Second, we talk about the same permission set but on the list level.
Let’s say we have taken the reference of lstContacts and wants the check for the same view list items permission, then
if(objList.DoesUserHavePermissions(SPBasePermissions.ViewListItems))
{
// your code goes here
}
And at last the same with each item of list / doc lib as SPListItem object objItem.
if(objItem.DoesUserHavePermissions(SPBasePermissions.ViewListItems))
{
// your code goes here
}
This method actually does not throw the exception if the permission is not there for the user, but there is one more method which does exactly the same thing, but throws the exception if the permission is not there for the user.
e.g. objWeb.CheckPermissions(SPBasePermissions.ViewListItems)
Above method checks the permission for the current user, but sometimes you may also require to check the same permission for some other user, well in that case, use the same method with overloaded method which has first parameter as string which takes the Login with domain name.
objItem.DoesUserHavePermissions({loginname}, SPBasePermissions.ViewListItems))
Well sometimes i think, is the name of this method correct? I mean shouldn't it be DoesUserHasPermission? if we see real grammer? your thoughts on this, readers? :)
Thank you
1 comment:
Nice post
And about the method's name, you're completely mistaken!! it MUST be (DoesUserHave...) but why? Ask a grammar expert :)
Post a Comment