views:

82

answers:

3

Hi,

What I need to add data to SPList and update Membership account by anonymous 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.

+1  A: 

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.

Tom Clarkson
+1 for reading my blog.
Kobi
+1  A: 

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.

Janis Veinbergs
A: 

Your code appears to be missing calls to web.Update or item.Update. Until you call update, nothing gets saved.

Tom Clarkson