What I need to add data to SPList and update Membership account by anonymo开发者_如何学Gous account. Simpler: I'm trying to write activation procedure of anonymous user already registered account.
I was trying to do this using mechanism of elevating permissions, but it fails. Is there any way to hard code credentials of some user, log in before some operations, then log out? And everything have to be done inside my own custom webpart.
You will do better if you create SPSite instance impersonated with system account as it results in a more stable code.
I had issues using RunWithElevatedPrivileges. Ofcourse you ned RunWithElevatedPrivileges when, for example, interacting with filesystem etc.
You do have the option of using impersonation or connecting through the web services. However, I would recommend finding out exactly why elevation isn't working. Take a look at http://kobikobi.wordpress.com/2009/05/04/adding-items-to-a-sharepoint-list/ - elevation is not necessarily all that you need to do.
Your code appears to be missing calls to web.Update or item.Update. Until you call update, nothing gets saved.
精彩评论