I have an application page and am trying to save settings for it using an SPPersistedObject. One of the fields I am saving needs to be encrypted and I tried to use SPEncryptedString but I can't get it to work.

Every time I call the UpdateSecureStringValue method to set the SPEncryptedString's SecureString with the value I need to store (after creating a SecureString with it), a SecurityException ("Access denied.") is thrown.

Can anyone tell me what I am doing wrong or possibly point me to some code that works?

1 Answer 1


In order to execute method SPEncryptedString in application page, the user should be logged in as farm account (administration in server farm)

Use the following method to check whether the current user is an administrator in the server farm: CurrentUserIsAdministrator


Lets suppose we need the ability to store connection strings

  1. Create object for storing connection strings (source). Connection strings are stored as encrypted strings.
  2. And create the administration page (source for code behind). Here we use not a regular application page but an administration page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.