Skip to content
DocsTry Aspire
DocsTry

IUserSecretsManager Methods

InterfaceMethods4 members
Defines an interface for managing user secrets with support for read and write operations.
GetOrSetSecret(IConfigurationManager, string, Func<string>)Section titled GetOrSetSecret(IConfigurationManager, string, Func<string>)abstract
Gets a secret value if it exists in configuration, or sets it using the value generator if it doesn't.
public interface IUserSecretsManager
{
public abstract void GetOrSetSecret(
IConfigurationManager configuration,
string name,
Func<string> valueGenerator)
{
// ...
}
}
configurationIConfigurationManagerThe configuration manager to check and update.
namestringThe name of the secret.
valueGeneratorFunc<string>Function to generate the value if it doesn't exist.
SaveStateAsync(JsonObject, CancellationToken)Section titled SaveStateAsync(JsonObject, CancellationToken)abstractTask
Saves state to user secrets asynchronously (for deployment state manager). If multiple callers save state concurrently, the last write wins.
public interface IUserSecretsManager
{
public abstract Task SaveStateAsync(
JsonObject state,
CancellationToken cancellationToken = default(CancellationToken))
{
// ...
}
}
stateJsonObjectThe state to save as a JSON object.
cancellationTokenCancellationTokenoptionalCancellation token.
TryDeleteSecret(string)Section titled TryDeleteSecret(string)virtualbool
Attempts to delete a user secret value synchronously.
public interface IUserSecretsManager
{
public virtual bool TryDeleteSecret(
string name)
{
// ...
}
}
namestringThe name of the secret.
boolTrue if the secret was deleted successfully; otherwise, false.
The default implementation returns false so existing implementations remain compatible.
TrySetSecret(string, string)Section titled TrySetSecret(string, string)abstractbool
Attempts to set a user secret value synchronously.
public interface IUserSecretsManager
{
public abstract bool TrySetSecret(
string name,
string value)
{
// ...
}
}
namestringThe name of the secret.
valuestringThe value of the secret.
boolTrue if the secret was set successfully; otherwise, false.