asp.net-core-2.1

NLog not writing to eventlog .NET Core 2.1

戏子无情 提交于 2019-12-08 03:13:15
问题 I've added NLog to my .NET core console app and it works with file and database targets. However when i try and get it to work with eventviewer it doesn't log anything. When i add the code for the eventviewer target the file and database part doesn't log anything. When I remove it, the logging starts working again. I have added a new event viewer source for the application using Powershell, so that wouldn't be the issue. The application doesn't crash or report an error, it runs fine but doesn

Rights-based authorization with ASP.NET Core 2.1 Identity

六月ゝ 毕业季﹏ 提交于 2019-12-08 00:55:47
问题 In the past, with ASP.NET MVC on .NET Framework, I always implemented a Rights-based authorization layer on top of the Roles-based authorization that was built-in. By "Rights-based", what I mean is that a list of enumerated Rights are assigned to each Role, and at runtime, each call checked for a Right, not a Role. e.g. say the Post method on the OrdersController required the AddOrEditOrder Right. That would look like [MyAuthorize(MyRights.AddOrEditOrder)] on the Post action. Then somewhere

Angular 7 to dotnetcore 2.1 web api call gives no response

爷,独闯天下 提交于 2019-12-07 09:01:27
问题 below is the code from login.component.ts, login() { const val = this.form.value; if (val.email && val.password) { this.authService.login(val.email, val.password) .subscribe( data => { if (data && data.Token) { // store user details and jwt token in local storage to keep user logged in //between page refreshes localStorage.setItem('currentUser', JSON.stringify(data)); console.log("user logged in"); this.router.navigate([this.returnUrl]); } else { console.log("user not logged in"); } }, error

.Net Core Identity 2 Provider login Cancel leads to unhandled exception

╄→гoц情女王★ 提交于 2019-12-07 04:06:44
问题 I've added LinkedIn as a provider. I have implemented the login and register with LinkedIn without any issue. In the use case where the user CANCELS from within the provider Pages (either linkedIn login or cancels the authorization of the app) the identity middleware seems to throw an unhandled exception: An unhandled exception occurred while processing the request. Exception: user_cancelled_login;Description=The user cancelled LinkedIn login Unknown location Exception: An error was

NLog not writing to eventlog .NET Core 2.1

陌路散爱 提交于 2019-12-06 16:05:31
I've added NLog to my .NET core console app and it works with file and database targets. However when i try and get it to work with eventviewer it doesn't log anything. When i add the code for the eventviewer target the file and database part doesn't log anything. When I remove it, the logging starts working again. I have added a new event viewer source for the application using Powershell, so that wouldn't be the issue. The application doesn't crash or report an error, it runs fine but doesn't log anything when event viewer is included. <nlog xmlns="http://www.nlog-project.org/schemas/NLog

How to set ShutdownTimeout using HostBuilder Generic Host ref StopAsync OperationCanceledException

Deadly 提交于 2019-12-06 12:57:28
Looking into the source code , the default Timeout for StopAsync is 5 seconds. WebHostBuilder provides an extension method UseShutdownTimeout for easy setting. But no such equivalent exists for HostBuilder . I know I'm probably abusing the intent of HostBuilder by wanting more than 5 second timeout, but it's a nice framework for managing a collection of interdependent jobs. I'd really appreciate some guidance on how to do with HostBuilder what UseShutdownTimeout does for WebHostBuilder whilst still working with official NuGet packages. I had a look at maybe extending

.net core get user in ValidationAttribute

核能气质少年 提交于 2019-12-06 09:12:47
I am trying to access the current user (i.e. ClaimsPrincipal from identity) in a custom ValidationAttribute, and I haven't figured out how I could do that. public class UniqueTitleValidator : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { // var user = ? } } I know that I could access the user from a HttpContext (but I don't know how to get to the latter). The main problem is that I don't have access to the User. When I use a custom ValidatorAttribute on a property, when the property gets constructed the User (or also

Change Bound Property in OnPost in model is invalid

放肆的年华 提交于 2019-12-06 07:24:50
I am using ASP.NET Core Razor Pages and I want to add a counter for a number of attempts it takes a user complete a task. I am using: [BindProperty] public int Attempts { get; set; } And inside the OnPost I am doing this: public IActionResult OnPost() { if(!IsCorrect()) { Attempts++; return Page(); } return RedirectToPage($"./Index") } I expected this to update the data on the client side, since without [BindProperty] & return Page() , data would be lost if the model was invalid. However, Attempts never increases on the client. I think I may have misunderstood how this works? Any suggestions?

.net core - unit of work generic repository pattern

扶醉桌前 提交于 2019-12-06 06:41:12
问题 I am Looking to migrate a large project that gathers information about products. The current application uses CSLA as its framework (traditional aspx forms). I am wanting to migrate / develop the application over to .net core 2.1. I have experience of developing in MVC (4+ years) and some recent exposure to .net core. I am wanting to use EF Core to call the existing stored procedures. I am looking at using the Unit of Work Generic repository design pattern. I have used the repository pattern

Rights-based authorization with ASP.NET Core 2.1 Identity

回眸只為那壹抹淺笑 提交于 2019-12-06 05:35:17
In the past, with ASP.NET MVC on .NET Framework, I always implemented a Rights-based authorization layer on top of the Roles-based authorization that was built-in. By "Rights-based", what I mean is that a list of enumerated Rights are assigned to each Role, and at runtime, each call checked for a Right, not a Role. e.g. say the Post method on the OrdersController required the AddOrEditOrder Right. That would look like [MyAuthorize(MyRights.AddOrEditOrder)] on the Post action. Then somewhere else you'd be able to configure that only the Manager and CustomerRep Roles had that Right. I always