在我的web.config中的AppSettings中,我有这样的事情:
<appSettings>
<add key="ExternalSystemUrl" value="http://domain.com/page.aspx?id={0}&action=eat&object=bacon" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
但是,似乎当一个&符号(&)包含在AppSettings值中时,ASP.NET会抛出以下错误:
解析EntityName时发生错误
为什么会发生这种情况,如何在App.config中包含这样的URL?
我目前正在学习这些教程,并且我想从Azure的Web应用程序设置中调用明文字符串.我的印象是环境变量用于非配置文件.但是,我想对web.config文件使用相同的方法.
<connectionStrings configSource="/config/ConnectionStrings.config">
<add name="DefaultConnection" connectionString="@Environment.GetEnvironmentalVariable('SQLAZURECONNSTR_DefaultConnection')" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings file="config\AppSettingsSecret.config">
<!-- Code Removed for Conciseness-->
<add key="mailAccount" value="@Environment.GetEnvironmentalVariable('APPSETTING_mailAccount')" />
<add key="mailPassword" value="@Environment.GetEnvironmentalVariable('APPSETTING_mailPassword')" />
<!-- Twilio-->
<add key="TwilioSid" value="@Environment.GetEnvironmentalVariable('APPSETTING_TwilioSid')" />
<add key="TwilioToken" value="@Environment.GetEnvironmentalVariable('APPSETTING_TwilioToken')" />
<add key="TwilioFromPhone" value="@Environment.GetEnvironmentalVariable('APPSETTING_TwilioFromPhone')" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
注意:我在本地测试中包含了configSource ="/ example /".
是否有人知道我可以在.Net应用程序中设置应用程序当前开发模式的应用程序(或用户)级别设置?IE:调试/发布
更具体地说,我有一个url引用我的应用程序设置中保存的webservices.在发布模式期间,我希望这些设置在调试模式期间指向http://myWebservice.MyURL.com我希望这些设置为http://myDebuggableWebService.MyURL.com.
有任何想法吗?
我试图在我的appsettings.json文件中编写我的连接字符串并将其带入我的启动文件但我不断得到一个值不能为空.参数名称:connectionString.我一直在使用各种示例,但似乎无法看到ASP.NET 1.0 Core启动类的这个新设置.
Appsetting.json文件:
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Data Source=server;Initial Catalog=dbase;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
尝试Startup.cs的方法
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public void ConfigureServices(IServiceCollection services)
{
var connStr = Configuration.GetConnectionString("DefaultConnection");
System.Console.WriteLine(connStr);
services.AddDbContext<DbContext>(options => options.UseSqlServer(connStr)); //error right here -- Null value
}
Run Code Online (Sandbox Code Playgroud) 我目前正在使用asp.net core v1.1开发项目,在我的appsettings.json中我有:
"AppSettings": {
"AzureConnectionKey": "***",
"AzureContainerName": "**",
"NumberOfTicks": 621355968000000000,
"NumberOfMiliseconds": 10000,
"SelectedPvInstalationIds": [ 13, 137, 126, 121, 68, 29 ],
"MaxPvPower": 160,
"MaxWindPower": 5745.35
},
Run Code Online (Sandbox Code Playgroud)
我也有用来存储它们的类:
public class AppSettings
{
public string AzureConnectionKey { get; set; }
public string AzureContainerName { get; set; }
public long NumberOfTicks { get; set; }
public long NumberOfMiliseconds { get; set; }
public int[] SelectedPvInstalationIds { get; set; }
public decimal MaxPvPower { get; set; }
public decimal MaxWindPower { get; set; …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Web应用程序,它需要一个用户名和密码存储在web.Config中,它还指的是一些URL将由Web应用程序本身而不是客户端请求.
我知道.Net框架不允许提供web.config文件,但我仍然认为将此类信息保留为纯文本是不好的做法.
到目前为止我读过的所有内容都要求我使用命令行开关或将值存储在服务器的注册表中.我可以访问这两个,因为主机在线,我只有FTP和控制面板(helm)访问.
任何人都可以推荐任何好的,免费的加密DLL或我可以使用的方法吗?我宁愿不发展自己的!
感谢您的反馈到目前为止,但我无法发出命令,也无法编辑注册表.它必须是一个加密工具/助手,但只是想知道哪一个!
我需要始终知道用户在推送通知设置中选择了哪些选项.
(选项包括 - 警报,声音和徽章)
所以,当我的应用程序启动时,我打
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
Run Code Online (Sandbox Code Playgroud)
并检测用户选择的内容.
但是,如何在应用程序生命周期内检测用户是否稍后更改设置?
是否有一些委托方法在此设置发生更改时被调用?
iphone objective-c appsettings push-notification apple-push-notifications
在两个项目(.NET Core Web API和.NET Core WindowsService)中,我使用appsettings.json进行配置.
var configuration = new ConfigurationBuilder()
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
Run Code Online (Sandbox Code Playgroud)
在两者中,我将reloadOnChange设置为true并使用它作为IOptions依赖注入注入.在web api中进入控制器类,在服务内进入使用设置的类.
不幸的是,我发现appsettings.json更改时值不会改变.
在web api上,我创建了一个控制器,只是从配置中返回一个字符串值,这与启动时保持一致.
所以我的问题:
我在VS 2017中进行azure功能开发.我需要设置一些自定义配置参数.我把它们添加到了local.settings.json下面Values.
{
"IsEncrypted":false,
"Values" : {
"CustomUrl" : "www.google.com",
"Keys": {
"Value1":"1",
"Value2" :"2"
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,ConfigurationManager.AppSettings["CustomUrl"]返回null.
.Net框架: 4.7
Microsoft.NET.Sdk.Functions: 1.0.5
System.Configuration.ConfigurationManager:4.4.0
Azure.Functions.Cli: 1.0.4
我错过了什么吗?
我有这个应用程序,它使用 来appsettings.json存储一些配置,例如 API 地址、令牌、保存文件的路径等。
我们没有 DevOps,因此对于我们在应用程序设置中所做的每项更改,我们需要要求基础架构团队将更改部署到生产中。
也就是说,我在想是否可以将一些配置放入数据库和Startup构造函数中,或者ConfigureServices从数据库中获取此信息并在应用程序中使用它。
例如,每次我向应用程序设置添加新密钥时,都不需要进行新的部署。我只需在数据库中创建一条新记录,应用程序将使用此配置,就像它在应用程序设置中一样。
今天我们有这个:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有可行的或可能的类似的事情:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.GetConfigFromDataBase() /// And this will be the method to get from DB the dynamic configuration
.AddEnvironmentVariables();
Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)
是否可以?或者我正在尝试重新发明轮子?
预先感谢您的宝贵时间!
database asp.net-mvc configuration-files appsettings asp.net-core-2.1
appsettings ×10
json ×4
asp.net-core ×3
c# ×3
.net ×2
.net-core ×2
asp.net-mvc ×2
azure ×2
web-config ×2
asp.net ×1
database ×1
encryption ×1
iphone ×1
objective-c ×1
security ×1
settings ×1
vb.net ×1