asp.net-core-2.0

What is the markdown syntax for .NET Core templating

只谈情不闲聊 提交于 2020-07-21 07:31:48
问题 I have a .NET Core template and wondering how I can hide partial content from markdown file based on the flags set? As you may see below I tried what I do in CS project files but it didn't work. README.md # Steps - createSolutionFile.ps1 <!--#if (CacheSqlServer)--> - sql-cache.ps1 1. create database `DistributedCache` 2. create schema `cache` 3. run the script <!--#endif--> - user-secrets.ps1 <!--#if (EntityFramework)--> - scaffold.ps1 - migrate.ps1 <!--#endif--> - build.ps1 <!--#if

Adding handler to default http client in ASP.NET Core [duplicate]

走远了吗. 提交于 2020-07-21 06:27:18
问题 This question already has an answer here : adding a handler to all clients created via IHttpClientFactory? (1 answer) Closed 4 days ago . Is there a way to add handlers to the default HTTP client in ASP.NET Core? Something like this? .AddHttpClient() .AddHttpMessageHandler<Handler1>() .AddHttpMessageHandler<Handler2>(); 回答1: Documentation states that you can only add handlers or configure the inner most handler to named or typed clients. Reference Configure the HttpMessageHandler It may be

Creating an Azure ServiceBus Queue via code

拥有回忆 提交于 2020-07-19 04:56:05
问题 Apologies, I'm new to Azure. I created a service bus and queue via the Azure portal using this tutorial. I can write and read from the queue ok. The problem is, to deploy to the next environment, I have to either update the ARM template to add the new queue or create the queue in code. I can't create the queue through the portal in the next environment. I've chosen the latter: check to see if the queue exists and create as required via code. I already have an implementation for this for a

PostgresException: 23505: duplicate key value violates unique constraint “PK_country”

点点圈 提交于 2020-07-18 20:58:20
问题 I am using EF Core 2.0 and Postgres 9.6. Whenever I insert data I get the error PostgresException: 23505: duplicate key value violates unique constraint "PK_country" By tracing it looks like EF doesnt generate AutoIncrement column My Model public partial class Country { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int CountryId { get; set; } [Display(Name="Country Name")] public string CountryName { get; set; } } My Controller if (ModelState.IsValid) { _context.Add

PostgresException: 23505: duplicate key value violates unique constraint “PK_country”

烈酒焚心 提交于 2020-07-18 20:57:04
问题 I am using EF Core 2.0 and Postgres 9.6. Whenever I insert data I get the error PostgresException: 23505: duplicate key value violates unique constraint "PK_country" By tracing it looks like EF doesnt generate AutoIncrement column My Model public partial class Country { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int CountryId { get; set; } [Display(Name="Country Name")] public string CountryName { get; set; } } My Controller if (ModelState.IsValid) { _context.Add

instance of entity type cannot be tracked because another instance with same key value is tracked

跟風遠走 提交于 2020-07-18 04:30:38
问题 I'm using generic repository pattern in asp.net core 2.0 which can not dispose repository object, when I am going to update the entry its updated for one time successfully but when I am trying to update for more then once it throws the following exception: The instance of entity type 'Company' cannot be tracked because another instance with the same key value for {'ID'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is

How to write log4net config into appsettings.json?

南笙酒味 提交于 2020-07-17 06:38:52
问题 I have implemented log4net into .NET core 2.0 , to log into a text file. As log4net have a config file, which is having XML configuration in it. So, I have created a separate file log4net.config to set its configuration and it is working fine. But I want to set its configuration into appsettings.json . Is it possible to write the log4net configuration into appsettings.json . <appSettings> <add key="IsLog" value="True" /> <add key="MaxThreads" value="3" /> </appSettings> <log4net debug="false"

How to write log4net config into appsettings.json?

耗尽温柔 提交于 2020-07-17 06:37:35
问题 I have implemented log4net into .NET core 2.0 , to log into a text file. As log4net have a config file, which is having XML configuration in it. So, I have created a separate file log4net.config to set its configuration and it is working fine. But I want to set its configuration into appsettings.json . Is it possible to write the log4net configuration into appsettings.json . <appSettings> <add key="IsLog" value="True" /> <add key="MaxThreads" value="3" /> </appSettings> <log4net debug="false"

Asp.net core 2.0 Jwt doesn't ignore AllowAnonymous

故事扮演 提交于 2020-07-11 06:23:32
问题 I'm making a small new project using .net core 2.0 and jwt bearer authentication (https://github.com/aspnet/Security) Here is my Startup.cs /// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { // Add entity framework to services collection. var sqlConnection = Configuration.GetConnectionString("SqlServerConnectionString");

Entity Framework Database First .Net Core

[亡魂溺海] 提交于 2020-07-06 10:45:41
问题 I have a .Net Standard 2.0 class library project and I want to add Entity Framework to it. I have added the Entity Framework Core package to the project but no Entity Framework Templates appear when I try to add a new item to the project. I have looked on the web and all I can seem to find is instructions for Code First! How do I get the database first functionality back? 回答1: EF Core does not, and will never, support the EDMX-based Database First workflow with the designer. EF Core stores