Bla*_*man 8 .net c# security configuration windows-services
我想将我的Windows服务'登录的用户名/密码信息存储为app.config中的'用户.
所以在我的安装程序中,我试图从app.config中获取用户名/密码并设置属性,但是在尝试安装服务时遇到错误.
如果我硬编码用户名/密码,它工作正常,当我尝试访问app.config时失败
public class Blah : Installer
{
public Blah()
{
ServiceProcessInstaller oServiceProcessInstaller = new ServiceProcessInstaller();
ServiceInstaller oServiceInstaller = new ServiceInstaller();
oServiceProcessInstaller.Account = ServiceAccount.User;
oServiceProcessInstaller.Username = ConfigurationManager.AppSettings["ServiceProcessUsername"].ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
小智 13
关于访问安装程序中的配置文件的一些想法.
Configuration config = ConfigurationManager.OpenExeConfiguration(assemblyPath);
ConnectionStringsSection csSection = config.ConnectionStrings;
Run Code Online (Sandbox Code Playgroud)
Assembly Path可以通过以下几种方式获得:内部Installer类实现:
this.Context.Parameters["assemblypath"].ToString();
Run Code Online (Sandbox Code Playgroud)
或有时反思:
Assembly service = Assembly.GetAssembly(typeof(MyInstaller));
string assemblyPath = service.Location;
Run Code Online (Sandbox Code Playgroud)
问题是,当您的安装程序运行时,您仍处于安装阶段,并且您的应用程序尚未完全安装.app.config仅在运行实际应用程序时可用.
但是,您可以执行以下操作:
| 归档时间: |
|
| 查看次数: |
13785 次 |
| 最近记录: |