2014-10-18 53 views
0

我已經安裝了VS2013 Professional,提出了一個應用程序並希望部署它,但問題是,「Visual Installer」似乎並不存在,我也不想要「ClickOnce」。VisualStudio安裝程序沒有顯示

還有一件事是數據庫信息是在app.config中,我怎麼能讓它沒有人看到數據庫信息?

+0

安裝程序指的是MSI安裝程序?如果是這樣,比你應該知道vdproj項目模板(允許創建msi pacakges的項目)不再受支持,因爲VS 2012.你可以使用VS的InstallShield限制版(ISLE)(谷歌它的說明)或學習WiX(Windows Installer Xml)是另一種通過可配置的xml文件創建MSI包的方式。 – Roman 2014-10-18 17:34:17

+0

如果您不想單擊一次,只需從bin \ release文件夾複製EXE文件即可。 – RadioSpace 2014-10-18 17:37:27

+1

@Roman他們帶回2013年,但沒有內置。你必須安裝它[作爲擴展](https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d) – 2014-10-19 06:12:20

回答

0

回答你的第二個問題上加密app.config文件是相當簡單的,易於使用:

受保護的配置提供幫助,以保護敏感信息的配置文件的部分加密應用程序。這將導致攻擊者難以獲取敏感信息。 .NET框架提供保護的配置提供的方法有兩種:

  1. RSAProtectedConfigurationProvider:本品採用RSACryptoServiceProviderto加密配置部分
  2. DPAPIProtectedConfigurationProvider:本品採用Windows數據保護API(DPAPI)來加密配置部分。

    static void Main(string[] args) 
    { 
        string userNameWithoutEncryption = ConfigurationManager.AppSettings["username"]; 
        EncryptAppSettings("appSettings"); 
        string userNameWithEncrytionApplied = ConfigurationManager.AppSettings["username"]; 
    } 
    
    
    
    private static void EncryptAppSettings(string section) 
    { 
        Configuration objConfig = ConfigurationManager.OpenExeConfiguration(GetAppPath() + "AppKeyEncryption.exe"); 
        AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection(section); 
        if (!objAppsettings.SectionInformation.IsProtected) 
        { 
         objAppsettings.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider"); 
         objAppsettings.SectionInformation.ForceSave = true; 
         objConfig.Save(ConfigurationSaveMode.Modified); 
        } 
    } 
    
    
    private static string GetAppPath() 
    { 
        System.Reflection.Module[] modules = System.Reflection.Assembly.GetExecutingAssembly().GetModules(); 
        string location = System.IO.Path.GetDirectoryName(modules[0].FullyQualifiedName); 
        if ((location != "") && (location[location.Length - 1] != '\\')) 
         location += '\\'; 
        return location; 
    } 
    

要解密需要調用這個方法app.config文件:

private static void DecryptAppSettings(string section) 
    { 
     Configuration objConfig = ConfigurationManager.OpenExeConfiguration(GetAppPath() + "AppKeyEncryption.exe"); 
     AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection(section); 
     if (objAppsettings.SectionInformation.IsProtected) 
     { 
      objAppsettings.SectionInformation.UnprotectSection(); 
      objAppsettings.SectionInformation.ForceSave = true; 
      objConfig.Save(ConfigurationSaveMode.Modified); 
     } 
    } 

在上面的部分描述了加密的配置文件,以保護像密碼的敏感信息的方式。現在,如果我們想在配置文件被加密後在某個時候更改密鑰值,那麼我們無法輕鬆更新密碼。不用擔心.NET框架提供了這樣做的方式下面給出:

private static void UpdateKey(string newValue) 
    { 
     ExeConfigurationFileMap configFile = new ExeConfigurationFileMap(); 
     configFile.ExeConfigFilename = ConfigurationManager.AppSettings["configPath"]; 
     Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None); 
     config.AppSettings.Settings["password"].Value = newValue; 
     config.Save(); 
    } 

欲瞭解更多信息,這裏是我發現這個解決方案,並測試它自己:http://www.a2zmenu.com/blogs/csharp/how-to-encrypt-configuration-file.aspx

我希望這可以幫助你它爲我工作!

相關問題