sharepoint - Strange behavoir of RunWithElevatedPrivileges in Console Aplication with FBA -
- i have named site collection fba on und use activedirectorymembershipprovider.
- we have farm administrator domain\administrator. not explicitly sitecollection administrator.
i created sample console application run under domain\administrator account. in code that:
using (spsite site = new spsite(serverurl)) { using (spweb web = site.openweb()) { console.writeline(web.currentuser.loginname); console.writeline(windowsidentity.getcurrent().name); string username = "domain\\testuser"; spuser spuser = web.ensureuser(username); spgroup group = web.sitegroups["groupname"]; group.adduser(spuser); group.update(); } }
the console output domain\administrator become accessdenied exception when try add user group. when run runwithelevetadprivileges (which according posts read should have no influence in console app) , set allowunsafeupdates = true (the same story) code goes smoothly through, no exception thrown , user added group. interesting thing user written console output still domain\administrator.
so question is: wtf? there better way? why happenning? has had problem? should use membershipprovider?
small hint: when fba off become no exceptions.
runwithelevatedprivileges runs code permissions of user application pool runs. can other administrator. sure same result runwithelevatedprivileges?
anyway, better, more reliable way of elevating privileges pass system users user token in spsite constructor. try it.
Comments
Post a Comment