我已经安装了VS2013 Professional,提出了一个应用程序并希望部署它,但问题是,“Visual Installer”似乎并不存在,我也不想要“ClickOnce”。VisualStudio安装程序没有显示
还有一件事是数据库信息是在app.config中,我怎么能让它没有人看到数据库信息?
我已经安装了VS2013 Professional,提出了一个应用程序并希望部署它,但问题是,“Visual Installer”似乎并不存在,我也不想要“ClickOnce”。VisualStudio安装程序没有显示
还有一件事是数据库信息是在app.config中,我怎么能让它没有人看到数据库信息?
回答你的第二个问题上加密app.config文件是相当简单的,易于使用:
受保护的配置提供帮助,以保护敏感信息的配置文件的部分加密应用程序。这将导致攻击者难以获取敏感信息。 .NET框架提供保护的配置提供的方法有两种:
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。
我希望这可以帮助你它为我工作!
安装程序指的是MSI安装程序?如果是这样,比你应该知道vdproj项目模板(允许创建msi pacakges的项目)不再受支持,因为VS 2012.你可以使用VS的InstallShield限制版(ISLE)(谷歌它的说明)或学习WiX(Windows Installer Xml)是另一种通过可配置的xml文件创建MSI包的方式。 – Roman 2014-10-18 17:34:17
如果您不想单击一次,只需从bin \ release文件夹复制EXE文件即可。 – RadioSpace 2014-10-18 17:37:27
@Roman他们带回2013年,但没有内置。你必须安装它[作为扩展](https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d) – 2014-10-19 06:12:20