开发者

Add text to config file and use it in code behind in asp.net

开发者 https://www.devze.com 2023-04-07 20:24 出处:网络
I am using AES encryption and generating a random salt, I am storing this random salt in the database.开发者_如何转开发. Before I store the value to the database I want to append a string to it. I wan

I am using AES encryption and generating a random salt, I am storing this random salt in the database.开发者_如何转开发. Before I store the value to the database I want to append a string to it. I want this string to be placed in config file. How can I store a string in config file and How can I call in to append it with my salt.


Something like

<appSettings>
      <add key="specialstring" value="value to append" />
</appSettings>

and access this by ConfigurationSettingsConfigurationManager.AppSettings["specialstring"] and append

Also you can use WebConfigurationManager in the same way instead of ConfigurationSettingsConfigurationManager


Set value in web-config file by below code snippet

<appSettings><add key="KeyForValue" value="ValueString" /></appSettings>

Get value in coding file by below code snippet

string strValuetoGet = ConfigurationManager.AppSettings["KeyForValue"]


put the string in the appSettings section of your web.config file, something like this:

<appSettings>
  ...
  <add key="mySaltPrefix" value="your value..." />
  ...
</appSettings>

then read it from your C# code in this way:

var mySaltPrefix = System.Configuration.ConfigurationManager.AppSettings["mySaltPrefix"];

to run this code you should add a reference to System.Configuration to your C# project.

0

精彩评论

暂无评论...
验证码 换一张
取 消