Tag: 配置

寻找.NET配置框架

由于我的下一个项目(很多SOA的东西),我需要一个基于组件的配置并存储在数据库中以启用集中管理。 app.config / web.config不支持任何这些要求(我知道有一些app-domains的黑客攻击)。 所有人都知道配置框架吗? 它没有必要免费。 我知道如何谷歌;-)但我很欣赏你已经使用过的框架的一些经验。 提前致谢! 弗洛

如何在代码而不是配置中创建WCF EndPointBehaviors?

我有以下Xml配置 我想用C#代码实现而不是使用配置。 我无法弄清楚使用webHttp将EndPoint作为REST服务公开的人。 ServiceHost serviceHost = new ServiceHost(singletonInstance, “http://localhost:1234/MyService/xml”); // Create Meta Behavior ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); behavior.HttpGetEnabled = true; serviceHost.Description.Behaviors.Add(behavior); Binding mexBinding = MetadataExchangeBindings.CreateMexHttpBinding(); serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, “mex”); WSHttpBinding httpBinding = new WSHttpBinding(SecurityMode.None); serviceHost.AddServiceEndpoint(typeof(MyService.IMyService), httpBinding, “rest”);

处理生产配置中的密码以进行自动部署

我在这里看到了相关的问题,但它们似乎并没有完全回答我的需要。 我们使用Powershell脚本来部署我们的应用程序,并且大多数环境(UAT等)的配置文件中的密码等信息都是纯文本。 这不是一个大问题,但是当谈到PREPROD和PROD时,这是一个大问题。 因此我们在配置中有一些标记,如“{{prompt-password}}”,它将提供登录对话框( Get-Credential ),执行部署的人员可以输入凭据并继续部署。 但这对自动部署没有实际帮助(意味着通过TeamCity等工具一键部署) 我应该使用非对称加密( http://msdn.microsoft.com/en-us/library/as0w18af.aspx ),其中密码使用公钥加密,在配置中输入,并存储私钥(如上所述)这里http://msdn.microsoft.com/en-us/library/tswxhw92.aspx )在“代理”中(如在TeamCity将触发部署的VM中,并且具有受限制的访问权限)运行自动部署并且它可以解密密码? 在密码学和东西上并不是很强大,但这听起来像是要走的路吗? 还有其他建议吗? 人们如何处理这种自动部署? 更新: 好的,我已经开始实施了它。 我在C#中编写了一个使用Crypography库的控制台应用程序。 该应用程序生成密钥: RSACryptoServiceProvider rsa = GetRsa(containerName); File.WriteAllText(“keys.kez”,rsa.ToXmlString(true)); 我也拿出了公钥: File.WriteAllText(“public.pke”, rsa.ToXmlString(false)); 将公钥提供给必须加密密码并要求他们在配置中输入密码的任何人。 将keys.kez文件放在必须运行部署的任何代理中。

使用ASP.NET动态设置CSS值

我正在一个网站上,图片和其他资源将位于与网站主要内容不同的域中。 我们将为主站点使用类似“www.example.com”的内容,然后使用“images.example.com”获取样式的所有额外资源等。 在开发网站时,我会将所有这些资源保存在本地开发中。 机器。 这里的挑战是在生产服务器和开发环境之间保持CSS引用的一致性。 我想要做的是创建一个web.config键,用于存储图像服务器的URL。 然后,当从开发切换到生产时,我可以只更改web.config值,一切都会完成。 有没有办法从配置或C#类中的某个位置动态或以其他方式向CSS文件添加值? 或者我是以错误的方式来做这件事的? 此外,如果有所不同,我只能使用.NET 2.0。 UPDATE 为了进一步扩展这一点,我知道我可以使用web.config设置服务器控件的URL。 这些已经动态生成。 我更感兴趣的是我有什么选择来修改(或做“ 某事 ”)静态CSS文件,这将允许我更改CSS中引用的背景图像资源等URL。 除了使用我的IDE查找/替换值之外,我还能做些什么吗? 也许某些事情可以通过部署脚本自动完成?

C#WCF System.Configuration.ConfigurationErrorsException:无法识别的元素’ManagedService’

在WCF应用程序中,我有一些自定义配置类可供app.config使用。 但是,我从WCF服务主机获取以下堆栈跟踪(它尝试在WCF服务的构造函数中检索自定义配置): System.Reflection.TargetInvocationException:调用目标抛出了exception。 —> System.Configuration.ConfigurationErrorsException:无法识别的元素’ManagedService’。 (Service.dll.config第8行)在System.Configuration.BaseConfigurationRecord.EvaluateOne(String []键,SectionInput输入,Boolean isTrusted,FactoryRecord factoryRecord,SectionRecord sectionRecord,Object parentResult)处于System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord,Object parentResult,Boolean getLkg,Boolean getRuntimeObject,Object&result,Object&resultRuntimeObject)at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey,Boolean getLkg,Boolean checkPermission,Boolean getRuntimeObject,Boolean requestIsHere,Object&result,Object&resultRuntimeObject)at System System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey,Boolean getLkg,Boolean chec).Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey,Boolean getLkg,Boolean checkPermission,Boolean getRuntimeObject,Boolean requestIsHere,Object&result,Object&resultRuntimeObject) 位于ManagementService.cs中ManagementService..ctor()的System.Configuration.ConfigurationManager.GetSection(String sectionName)的System.Configuration.BaseConfigurationRecord.GetSection(String configKey)中的kPermission,Boolean getRuntimeObject,Boolean requestIsHere,Object&result,Object&resultRuntimeObject):第42行—内部exception堆栈跟踪的结束—在System.Reflection.RuntimeConstructorInfo.Invoke的System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo方法,Object [] args,SignatureStruct&signature,RuntimeType declaringType)中(BindingFlags invokeAttr,Binder binder, Object []参数,CultureInfo文化) System.ServiceModel.ServiceHostBase.InitializeDescription上System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2&implementedContracts)的System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType)上的System.ServiceModel.Description.ServiceDescription.CreateImplementation(Type serviceType) (UriSchemeKeylection baseAddresses)位于Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService的Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type,ServiceKind kind)的System.ServiceModel.ServiceHost..ctor(类型serviceType,Uri [] baseAddresses) ServiceInfo […]

访问ASP.NET Core控制器内的连接字符串

我正在使用C#和.NET Framework 4.7开发ASP.NET Core 2.0.2 Web API。 我想从方法的控制器中获取appsettings.json的连接字符串。 我在Startup.cs中做到了: using Microsoft.Extensions.Configuration; public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString(“MyContext”))); […]

如何处理具有异步方法的对象?

我有这个对象PreloadClient实现IDisposable ,我想处理它,但在异步方法完成他们的调用后……这没有发生 private void Preload(SlideHandler slide) { using(PreloadClient client = new PreloadClient()) { client.PreloadCompleted += client_PreloadCompleted; client.Preload(slide); } // Here client is disposed immediately } private void client_PreloadCompleted(object sender, SlidePreloadCompletedEventArgs e) { // this is method is called after a while, // but errors are thrown when trying to access object state (fields, properties) } […]

AppSettings.json用于ASP.NET核心中的集成测试

我正在遵循本指南 。 我在API项目中有一个使用appsettings.json配置文件的appsettings.json 。 public class Startup { public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile(“appsettings.json”, optional: true, reloadOnChange: true) .AddEnvironmentVariables(); Configuration = builder.Build(); Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .ReadFrom.Configuration(Configuration) .CreateLogger(); } 我正在看的特定部分是env.ContentRootPath 。 我做了一些挖掘,看起来我的appsettings.json实际上并没有复制到bin文件夹,但是这很好,因为ContentRootPath返回了MySolution\src\MyProject.Api\ ,这是appsettings.json文件所在的位置。 所以在我的集成测试项目中,我有这个测试: public class TestShould { private readonly TestServer _server; private readonly HttpClient _client; public TestShould() { […]

永久禁用EF中的Configuration.ProxyCreationEnabled?

而不是必须在每个查询上执行以下操作,有没有办法只是全局设置该值? 模型视图中有一个延迟加载设置,但似乎没有ProxyCreation的设置。 using (var context = new LabEntities()) { **context.Configuration.ProxyCreationEnabled = false;** var Query = from s in context.EAssets .Include(“Server”).Include(“Type”).Include(“Type.Definition”) where (s.Type.Definition.b_IsScannable == true) && (s.Server.s_Domain == Environment.UserDomainName || s.Server.s_Domain == null) select s; var Entities = Query.ToList(); } 我并不完全理解这个选项的好处,但是我知道在visual studio中标记了所有带有乱码序列后缀的对象,并且使得调试器使用不合理。

我是否需要在配置文件中转义反斜杠?

我有一个配置文件myapp.exe.config。 在文件中,我有一个带有完整路径文件名的属性作为值。 如果我使用单反斜杠,它似乎有效。 那是, 也有效。 这样做的正确方法是什么?