I have given read only permisisons to a group of users. So they have no access to see listitem or any list.
I have create an application page with SPGridview
which binds the listitems in question.
This page can be accessed by this group.
The problem is that when I write code with supertoken like this:
SPSite SiteInUserContext = SPContext.Current.Site;
SPWeb webInUserContext = SPContext.Current.Web;
Guid webGuid = webInUserContext.ID;
Guid siteGuid = SiteInUserContext.ID;
var user = webInUserContext.AllUsers[@"SHAREPOINT\SYSTEM"];
var superToken = user.UserToken;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteGuid, superToken))
{
//my code
}
});
it's throwing an access denied of login User
.
But when I write below code :
SPSite SiteInUserContext = SPContext.Current.Site;
SPWeb webInUserContext = SPContext.Current.Web;
Guid webGuid = webInUserContext.ID;
Guid siteGuid = SiteInUserContext.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteGuid)
{
//my code
}
});
user are able to access this page with Gridview as well as also edit and add new listitems.
My doubt is in which situations we shoud use SuperUserToken
with SPSecurity.RunWithElevatedPrivileges in Sharepoint object model.