1

I would like to get the current user for use in an app.config file. I can't just use Environment.UserName like I can in the VB file. Essentially I'm trying to have the app email whichever user is logged in rather than hard-coding a specific user.

Something that would work like this...

<add key="EmailFrom" value=Environment.UserName />

Note: the "Environment.UserName" is the correct effect I would like to get.

Programmer
  • 459
  • 5
  • 20
  • More info is needed, what is System.UserID? What type of authentication is this? – JonH Dec 07 '15 at 15:05
  • It was just an example of how I would like to use the "user ID" in the config file. – Programmer Dec 07 '15 at 15:07
  • I'm not sure what you're asking. Are you just trying to load a value from config? Or dynamically update the config from some value discovered at runtime? – Mike Guthrie Dec 07 '15 at 15:10
  • I would like to be able to put a value for the key that is not hard-coded but rather is based on the current user. – Programmer Dec 07 '15 at 15:12
  • 3
    The config is meant for hardcoded values. You have the code to do any dynamic value. Why can't you do it in the code? – the_lotus Dec 07 '15 at 15:22
  • Does this answer your question? [Set app.config value to Environment.UserName](https://stackoverflow.com/questions/2313173/set-app-config-value-to-environment-username) – etherrien Jun 17 '21 at 22:42

0 Answers0