我在ASP.NET Core Api哪里使用appsettings。{environmentname} .json配置文件。然后,我还有具有不同环境选项的适当的launchSettings.json文件,因此我可以使用任何特定的环境设置文件运行。
在Startup.cs中,我们有一个条件设置,如果我们处于非产品环境中,则使用一组特定的Jwt authentication(只是关闭了一些验证检查),然后在产品中加载一个具有要打开的所有检查。
在我的本地主机上,当environment.IsDevelopment()返回true,而environment.IsProduction()返回false时,此方法效果很好。大!
但是,当我在构建过程中运行并部署到测试环境时,该environment.IsDevelopment()现在返回false。
我在Program.cs文件中添加了选项以添加ConfigurationBuilder,以便可以将变量传递给构建过程,如下所示:
dotnet restore
dotnet build --environment "Development"
dotnet publish -o ..\Artifacts
Run Code Online (Sandbox Code Playgroud)
我将发布相关文件以及相关代码以获取更多信息...
Program.cs
public static IWebHost BuildWebHost(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
return WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
.UseStartup<Startup>()
.UseNLog()
.Build();
}
Run Code Online (Sandbox Code Playgroud)
Startup.cs(ConfigureServices方法)
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
{
// removed code not relevant...
// options.TokenValidationParameters = Environment.IsProduction()
// options.TokenValidationParameters = Environment.IsEnvironment("Prod")
options.TokenValidationParameters = Environment.IsDevelopment()
? devTokenValidationParameters
: prodTokenValidationParameters;
// options.TokenValidationParameters = devTokenValidationParameters;
});
Run Code Online (Sandbox Code Playgroud)
为什么是辅助环境。{EnvironmentName}()检查在这里不起作用?
我有一个包含@ Html.DropDownListFor的视图.当窗体/视图加载时,如果其中一个模型属性具有值(IEnumerable),那么它将创建一堆带有相应数据的div.如果该属性没有任何值(又名Count()== 0),那么它应该在表单上显示一个按钮(它将为该属性创建数据).
因此,当用户从Dropdown中选择其中一个选项时,我会将ajax调用激活到填充当前表单/视图的完全相同的操作方法,但这次,它会在id字段中发送一个值.
我的动作方法中有一个断点,我确认它正在被击中,它具有正确的参数值,并为传递给视图的模型创建正确的数据,但是......当模型被发送到查看重新填充,表单上没有任何项目/控件更改.我甚至在cshtml文件中放置断点,并且它也会使用正确的数据.
所以,这是我的控制器:
public ActionResult Index(int? id)
{
var seasonId = id;
if (seasonId == null)
{
var player = _playerRepository.Query().FirstOrDefault(p => p.PlayerId == _userIdentity.PlayerId);
if (player.DefaultSeasonId != null)
seasonId = (int)player.DefaultSeasonId;
else
{
return View(new ScheduleModel
{
Player = player,
AvailableSeasons = _seasonRepository.Query().Select(s => s)
});
}
}
return View(CreateScheduleModelForSeason((int)seasonId));
}
Run Code Online (Sandbox Code Playgroud)
这是我的观点的开始:
@model LeagueManager.Models.ScheduleModel
@{
ViewBag.Title = "Schedule(s)";
}
<div class="row">
@Html.LabelFor(m => m.AvailableSeasons)
@Html.DropDownListFor(m => m.SelectedSeasonId, new SelectList(Model.AvailableSeasons, "SeasonId", "SeasonName"), new { id = "seasonSelect" …Run Code Online (Sandbox Code Playgroud) 我正在做这些连接:
from #lps_at_lines2 as l2
left join jobmatl as jm on l2.item = jm.item
inner join job as j on jm.job = j.job
and jm.suffix = j.suffix
Run Code Online (Sandbox Code Playgroud)
我不确定联合将如何解决,官方文档就像读取象形文字给我.
我的猜测是,首先#lps_at_lines2得到LEFT JOIN' jobmatl然后以某种方式job得到INNER JOIN'到jm之后.那是对的吗?
我正在尝试使用我的 .NET Core 项目配置 Azure WebJob。每次我在 Azure 中执行作业时,它都会告诉我错误:
通过使用以下格式 DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY 指向存储 Microsoft Azure WebJobs 运行时日志的 Microsoft Azure 存储帐户,确保在 Microsoft Azure 网站配置中设置名为 AzureWebJobsDashboard 的连接字符串。
这是我配置所有内容以及配置内容的代码:
private static void ConfigureServices(IServiceCollection serviceCollection)
{
// Optional: Setup your configuration:
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
// add any interfaces that will be needed here
serviceCollection.AddScoped<IBatchJobService, BatchJobService>();
// executes the job
serviceCollection.AddScoped<ExecuteBatchJobs, ExecuteBatchJobs>();
// One more thing - tell azure where your azure connection strings are
var connStringDashboard …Run Code Online (Sandbox Code Playgroud)