0

我一直在使用 Settings.settings 文件来存储应用程序数据。

<applicationSettings>
    <SLA_TestService.Properties.Settings>
      <setting name="AuthenticationName" serializeAs="String">
        <value>IBR</value>
      </setting>
      <setting name="AuthenticationPassowrd" serializeAs="String">
        <value>IBR</value>
      </setting>
    </SLA_TestService.Properties.Settings>
</applicationSettings>

我使用加密应用程序设置

aspnet_regiis -pe "applicationSettings/SLA_TestService.Properties.Settings" -app     "/SLAMobility"

我使用以下方式访问设置;

string pword = Properties.Settings.Default.AuthenticationPassowrd

但是它会引发以下错误;

ExceptionType=System.Configuration.ConfigurationErrorsException
StackTrace=
  at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
  at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
  at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
  at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
  at System.Configuration.ConfigurationManager.GetSection(String sectionName)
  at System.Configuration.ClientSettingsStore.ReadSettings(String sectionName, Boolean isUserScoped)
  at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
  at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
  at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
  at System.Configuration.SettingsBase.get_Item(String propertyName)
  at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
  at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
  at SLA_TestService.Properties.Settings.get_AuthenticationName() in C:\Users\Mananu\documents\visual studio 2010\Projects\SLA_TestService\SLA_TestService\Properties\Settings.Designer.cs:line 31
  at SLA_TestService.Controllers.ValuesController.GetValues() in C:\Users\Mananu\documents\visual studio 2010\Projects\SLA_TestService\SLA_TestService\Controllers\ValuesController.cs:line 15
  at lambda_method(Closure , Object , Object[] )
  at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
  at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
  at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)

我究竟做错了什么?提前致谢!!

4

1 回答 1

0

你打错字了,我相信。

在您的配置文件中,将“AuthenticationPassowrd”更改为“AuthenticationPassword”。

于 2012-11-04T10:12:36.803 回答