asp.net-core

Does .Net Core support User Secrets per environment?

我怕爱的太早我们不能终老 提交于 2021-02-20 19:08:27
问题 Let's say I have connection string for Development environment specified in appsettings.Development.json and connection string for the Staging environment specified in appsettings.Staging.json All I need to do to switch between Development and Staging is to navigate to Visual Studio Debug tab in project properties and change the value for ASPNETCORE_ENVIRONMENT environment variable. Now, of course I don't want to have connection string in appsettings.*.json for security reasons. So I move it

Using EF Core HasQueryFilter on navigation properties

℡╲_俬逩灬. 提交于 2021-02-20 13:52:57
问题 I'm trying to apply a filter to my queries for multi-tenancy but it doesn't allow me to apply the filter when the property is part of a navigation property: modelBuilder.Entity<Level>().HasQueryFilter(lvl => lvl.SchoolYear.TenantId == _tenantProvider.TenantId); Here, Level is the property I want filtered but the property to use for filtering which is TenantId is is inside Level.SchoolYear. If its a top-level property it works fine. How can I apply a global filter when the property I need for

How to read headers data in hub SignalR ASP.NET Core 2.1

天涯浪子 提交于 2021-02-20 09:47:26
问题 I'm trying to pass userId to hub on connection to signalR. This is how client sets up the connection: connection = new HubConnectionBuilder() .WithUrl("http://localhost:56587/hub", options => { options.Headers["UserId"] = loginTextBox.Text; }) .AddMessagePackProtocol() .Build(); How can I read this header in OnConnectedAsync() method in my hub? 回答1: To get Header Value as string: public override async Task OnConnectedAsync() { var httpCtx = Context.GetHttpContext(); var someHeaderValue =

How to read headers data in hub SignalR ASP.NET Core 2.1

折月煮酒 提交于 2021-02-20 09:47:00
问题 I'm trying to pass userId to hub on connection to signalR. This is how client sets up the connection: connection = new HubConnectionBuilder() .WithUrl("http://localhost:56587/hub", options => { options.Headers["UserId"] = loginTextBox.Text; }) .AddMessagePackProtocol() .Build(); How can I read this header in OnConnectedAsync() method in my hub? 回答1: To get Header Value as string: public override async Task OnConnectedAsync() { var httpCtx = Context.GetHttpContext(); var someHeaderValue =

C# ASP.NET Core - SocketException: No such host is known

北城以北 提交于 2021-02-20 09:11:59
问题 I am having issues which seem to be related calling a specific API asynchronously using HttpClient - the strange thing is that it doesn't happen all the time and can be solved by refreshing the page (sometimes once, sometimes multiple times). I thought this could be a local issue but hosting on Azure produces the same results. Raw exception details: System.Net.Sockets.SocketException (11001): No such host is known at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port,

C# ASP.NET Core - SocketException: No such host is known

夙愿已清 提交于 2021-02-20 09:11:37
问题 I am having issues which seem to be related calling a specific API asynchronously using HttpClient - the strange thing is that it doesn't happen all the time and can be solved by refreshing the page (sometimes once, sometimes multiple times). I thought this could be a local issue but hosting on Azure produces the same results. Raw exception details: System.Net.Sockets.SocketException (11001): No such host is known at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port,

C# ASP.NET Core - SocketException: No such host is known

≡放荡痞女 提交于 2021-02-20 09:09:55
问题 I am having issues which seem to be related calling a specific API asynchronously using HttpClient - the strange thing is that it doesn't happen all the time and can be solved by refreshing the page (sometimes once, sometimes multiple times). I thought this could be a local issue but hosting on Azure produces the same results. Raw exception details: System.Net.Sockets.SocketException (11001): No such host is known at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port,

Inherit (?) IdentityUser from another project

浪子不回头ぞ 提交于 2021-02-20 08:58:48
问题 I have multiple projects in my solution, all .NET Core 3.1. One of them is my core project (“ A Project ”) where I just have basic model classes with no methods or database access. For demonstration purposes, below are simplified versions of my Address.cs and User.cs files: public class Address { public int Id {get;set;} public string AddressText {get;set;} public virtual User User {get;set;} } public class User { public int UserId {get;set;} public int UserName {get;set;} public ICollection

How to fix network error in react-native when access localhost api

爱⌒轻易说出口 提交于 2021-02-20 06:50:23
问题 We're trying to connect to an API (.net core 2.2) from react-native (version 0.59), via localhost, both apparently running on the same ip, different ports, react-native on port 8080, and the api on the 44344, the issue happens the moment we fetch the url from react-native We’ve also tested running the url from Postman and everything seems ok, also from any of the web browser installed (safari/chrome), even we tested the browser INSIDE react-native iOS, and it works. Any api running outside

Getting property attributes in TagHelpers

試著忘記壹切 提交于 2021-02-20 06:50:14
问题 Some of model properties has "Required" data annotation, that I need to read in a TagHelper class. public partial class Sale { [Required] public string CustomerId { get; set; } ... In the sales view I create a custom select for customer: <customer asp-for="CustomerId " value="@Model.CustomerId"></customer> And in the CustomerTagHelper class there is the process method: public override void Process(TagHelperContext context, TagHelperOutput output) { How can I discover at this point, if the