asp.net-core-mvc

How to implement a UserFactory using IHttpContextAccessor

纵然是瞬间 提交于 2020-02-16 05:15:29
问题 I used to have a UserFactory (before vNext) that used HttpContext.Current but since that is now gone I am having trouble recreating it. I want it to be a static class that sets and gets the current user to access user data throughout the application. I know I must use the DI system but not sure how. Code so far: public class CurrentContext : IHttpContextAccessor { private IHttpContextAccessor ctx; public HttpContext HttpContext { get { return ctx.HttpContext; } set { ctx.HttpContext = value;

How to implement a UserFactory using IHttpContextAccessor

别说谁变了你拦得住时间么 提交于 2020-02-16 05:13:27
问题 I used to have a UserFactory (before vNext) that used HttpContext.Current but since that is now gone I am having trouble recreating it. I want it to be a static class that sets and gets the current user to access user data throughout the application. I know I must use the DI system but not sure how. Code so far: public class CurrentContext : IHttpContextAccessor { private IHttpContextAccessor ctx; public HttpContext HttpContext { get { return ctx.HttpContext; } set { ctx.HttpContext = value;

IValidatableObject.Validate doesn't get called on parent if validation fails on child

心已入冬 提交于 2020-02-15 09:44:53
问题 I can't find any details on this, but the issue I am having is that Validate function of parent object doesn't get called if Validate call fails on any child properties. Simple scenario below: public class Child : IValidateObject { public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { ... } } public class Parent : IValidatableObject { public Child Child { get; set;} public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { ... } } If

IValidatableObject.Validate doesn't get called on parent if validation fails on child

巧了我就是萌 提交于 2020-02-15 09:43:07
问题 I can't find any details on this, but the issue I am having is that Validate function of parent object doesn't get called if Validate call fails on any child properties. Simple scenario below: public class Child : IValidateObject { public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { ... } } public class Parent : IValidatableObject { public Child Child { get; set;} public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { ... } } If

IValidatableObject.Validate doesn't get called on parent if validation fails on child

允我心安 提交于 2020-02-15 09:40:43
问题 I can't find any details on this, but the issue I am having is that Validate function of parent object doesn't get called if Validate call fails on any child properties. Simple scenario below: public class Child : IValidateObject { public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { ... } } public class Parent : IValidatableObject { public Child Child { get; set;} public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { ... } } If

Visual Studio 2017 References vs Dependencies

安稳与你 提交于 2020-02-15 06:54:37
问题 I have a .NET Core solution in visual studio 2017 that is building against the .NET 4.7 framework. In the main web application there is a dependencies menu that breaks down references into logical categories (Analyzers, Assemblies, NuGet, Projects). In the helper project it only has a references menu with everything jumbled inside. Is there a way to get the same treatment here as the web application got? 回答1: It's based on the project file type. The older Full Framework project file gives you

.NET Core use AppUser as attribute in another model

筅森魡賤 提交于 2020-02-06 07:30:34
问题 So what I'm trying to do is associate an author with a post. The class AppUser extends from IdentityUser. I'm trying to set the author of each post as an AppUser, but I'm having some problems. In the database Author doesn't show up instead it's AuthorId, why is that? However it seems looks lika i can reach the AppUser from the post, I get no error or warnings. But i Still can't view the author name with help of the post, can someone please explain why? Post Model public class Post { ..... ...

.NET Core use AppUser as attribute in another model

前提是你 提交于 2020-02-06 07:30:25
问题 So what I'm trying to do is associate an author with a post. The class AppUser extends from IdentityUser. I'm trying to set the author of each post as an AppUser, but I'm having some problems. In the database Author doesn't show up instead it's AuthorId, why is that? However it seems looks lika i can reach the AppUser from the post, I get no error or warnings. But i Still can't view the author name with help of the post, can someone please explain why? Post Model public class Post { ..... ...

.NET Core use AppUser as attribute in another model

时间秒杀一切 提交于 2020-02-06 07:30:20
问题 So what I'm trying to do is associate an author with a post. The class AppUser extends from IdentityUser. I'm trying to set the author of each post as an AppUser, but I'm having some problems. In the database Author doesn't show up instead it's AuthorId, why is that? However it seems looks lika i can reach the AppUser from the post, I get no error or warnings. But i Still can't view the author name with help of the post, can someone please explain why? Post Model public class Post { ..... ...

Linq on EF7 doesnt work with Joins and Dates?

流过昼夜 提交于 2020-02-06 04:57:08
问题 I am having some troubles running a query from a Controller on my ASP.NET MVC6 EF7 web app... The Model and DbContext are in this previous ask: EF7 Incorrect configuration of the DBContext? The problem appears when I try to run the following Linq query which contains a couple of joins and tries to get some entries from a Database for a particular date... public IActionResult GetEntries(int year, int month, int day) { //_context.Database.SetCommandTimeout(180); string dateTest = new DateTime