Edit Key Value In AppSettings

Last post 10-30-2007 8:08 AM by anas. 3 replies.

Sort Posts:

  • Edit Key Value In AppSettings

    10-29-2007, 4:07 AM

    I have a key value in AppSettings.

    I want to edit its value permanently.

    But currently when I update it. It is updated for some times. And after some period. Its change back to old value.

  • Re: Edit Key Value In AppSettings

    10-29-2007, 3:39 PM
    • Member
      96 point Member
    • eRabbit
    • Member since 05-21-2007, 4:33 PM
    • Phoenix
    • Posts 26

     Are you sure you are not overriding the config file with an old config file when you update?  How are you migrating changes to the server?

     Otherwise I want to say that any value inside of an AppSettings type file is changeable, though you can restrict if its user sensitive or if it's global to the app.  If you want to make it something not modifiable, you should put it somewhere else inside of a static class of Constants.

     -A

     

     
     

  • Re: Edit Key Value In AppSettings

    10-30-2007, 12:03 AM

    I think I don't describe the issue correctly because you are going in some other direction.

    I want to use AppSettings Key Value Modifiable.

    But when I modify it. It is preserved for some time but after some interval changes back to old first value.

    But I want when I modifiy it then it will not change back to another value till I do it by coding.

  • Re: Edit Key Value In AppSettings

    10-30-2007, 8:08 AM
    Answer
    • All-Star
      59,282 point All-Star
    • anas
    • Member since 09-21-2006, 8:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,734
    • Moderator

    hi

    using appsettings("key")=value ...... will change the settings in memory and not in web.config

    to change it in both , use  this function :

    VB:

    Private Sub ChangeAppSettings(ByVal key As String, ByVal NewValue As String)
            Dim cfg As Configuration
            cfg = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
    
            Dim setting As KeyValueConfigurationElement = _
            CType(cfg.AppSettings.Settings(key), KeyValueConfigurationElement)
    
            If Not setting Is Nothing Then
                setting.Value = NewValue
                cfg.Save()
            End If
        End Sub
    

    C#: 

    private void ChangeAppSettings(string key, string NewValue) 
    { 
        Configuration cfg; 
        cfg = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); 
        
        KeyValueConfigurationElement setting = (KeyValueConfigurationElement)cfg.AppSettings.Settings(key); 
        
        if ((setting != null)) { 
            setting.Value = NewValue; 
            cfg.Save(); 
        } 
    } 
     

     

    Regards,

    Anas Ghanem | Blog

Page 1 of 1 (4 items)