使用替换方法更改密码 [英] Using replace method to change password

查看:177
本文介绍了使用替换方法更改密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用以下代码替换我的app.config中的密码.它会成功替换,但不会在内存中重新加载配置文件,因此数据集会给出错误的密码错误.请帮忙.

Hi,
I am using following code to replace the passwords in my app.config. It replaces successfully but does not reload config file in the memory so datasets give error of wrong password. Please help.

Dim vrTextFind As String = "Password"
    Dim vrTextReplaceWith As String = "PWD"
    Dim path As String = "D:\VS2008\EncTest\EncTest\bin\Debug\enctest.exe.config"
    Dim readText As String = File.ReadAllText(path)
    TextBox1.Text = readText
    ''Find
    Dim idx As Integer = 0
    idx = TextBox1.Text.IndexOf(vrTextFind, idx)
    If idx = -1 Then
        MessageBox.Show(vrTextFind & " is not in Textbox1")
    Else
        TextBox1.SelectionStart = idx
        TextBox1.SelectionLength = vrTextFind.Length
    End If
    ''Replace
    If TextBox1.Text.Contains(TextBox1.Text) Then
        TextBox1.Text = TextBox1.Text.Replace(vrTextFind, vrTextReplaceWith)
    Else
        MessageBox.Show(TextBox1.Text & " is not in Textbox3")
    End If
    ''''''''''
    ''Write all back
    File.WriteAllText(path, TextBox1.Text)
    ''Refreshes the connection string section
    ConfigurationManager.RefreshSection("connectionStrings")

推荐答案

亲爱的朋友,

与台式机应用程序一样,该应用程序已处于运行模式,或者已通过从app.config值中获取现有设置来加载该应用程序,并且该代码已被编译,因此它将始终采用该app.config的旧值.

为了采用新的app.config值(在您的情况下,它是密码),您必须重新编译/重新加载该应用程序.

希望您能理解.

谢谢
Dear Friend,

As in the desktop applications, the application is already in running mode OR it has been loaded by taking the existing setting from the app.config values and the code is already been compiled so it will always take the old values of the app.config.

In order to take the new values of app.config (in your case it is the password) you have to recompile/reload the application.

I hope you understand.

Thanks


您的应用程序不会监视它的app.config或在更改时重新加载它.您最好将其设置在某个地方以便立即使用.您将无法在Windows 7中的代码中更改此文件,应将可更改的配置数据存储在文件系统的app数据部分中.
Your app does not monitor it''s app.config or reload it when it changes. You''d do better to set it somewhere for immediate use. You will have problems changing this file in code in windows 7, you should store changable config data in the app data section of the file system


这篇关于使用替换方法更改密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆