asp.net-core-2.2

How do I dependency inject SignInManager?

蹲街弑〆低调 提交于 2019-12-24 18:23:27
问题 I have a WebAPI app which I'm using a 3rd party authenticator (Firebase authentication). I have the authentication working but once the user has logged into my server, I'd like to save credentials and user data into my ASP.NET Identity tables. I seem to be able to use the UserManager to create accounts if I call this line in my Startup.cs file services.AddIdentityCore<ApplicationUser>() .AddEntityFrameworkStores<ApplicationDbContext>(); This allows me to add UserManager in my constructor

ASP.Net Core 2.2 - separate serializer settings for input and output

流过昼夜 提交于 2019-12-24 07:31:03
问题 ASP.Net Core 2.2 allows to set serializer settings using MvcJsonOptions.SerializerSettings property. The problem is that it affects both input and output. Is there a way to have separate options for input (deserialization) and output (serialization)? In particular, I need to set a different behavior for NullValueHandling settings: ignore null errors for non-nullable fields when deserializing client json but keep nulls for defined model fields when serializing the result. For example, I have a

Quartz.NET 3.0 seems to launch all jobs in the same scope

◇◆丶佛笑我妖孽 提交于 2019-12-24 07:16:17
问题 I have a hard time using Quartz 3.0.7 with ASP.NET Core 2.2 after I have defined two jobs that rely on a scoped service (ScopedDataAccess) that is a wrapper upon my database context: services.AddScoped<IScopedDataAccess, ScopedDataAccess>(); services.AddDbContext<AggregatorContext>(opt => opt.UseSqlServer(configuration.GetConnectionString("Default"))); The issue is that both jobs receive the same instance of the scoped service (and thus the same database context), thus crashing the context

Unsupported Media Type on ASP.Net Core 2.2 ApiController

谁都会走 提交于 2019-12-24 04:05:16
问题 I have the following controller and actions: [ApiController, ApiVersion("1.0", Deprecated = false), Route("v{version:version}")] public class PostController : ControllerBase { [HttpGet("users/{userId}/posts")] public async Task<IActionResult> GetByUserId(GetModel model) { } [HttpPost("users/{userId}/posts")] public async Task<IActionResult> CreateByUserId(CreateModel model) { } } I tried to access both actions using Angular and Insomnia ... I am able to access CreateByUserId [POST] but I get

.net core console app as windows service- Is it possible to safely kill execution of started process without using Kill() method?

痴心易碎 提交于 2019-12-24 03:07:46
问题 I have a dotnet core 2.2 console app. I hosted it as windows service.(Service name: "MyService1") "MyService1" starts up another dotnet core WebAPI. The problem is, how do I safely kill the WebAPI process when the "MyService1" is stopped? Here is how I tried to do that but I can still see the process in the task manager. public class MyService : IHostedService, IDisposable { private Timer _timer; static Process webAPI; public Task StartAsync(CancellationToken cancellationToken) { _timer = new

ASP.NET Core Identity - LoginPartial broken after scaffolding identity

一笑奈何 提交于 2019-12-24 02:59:07
问题 I created a new Project from the VS 2017 template (web application with individual user accounts). This adds the ASP.NET Core Identity as default UI (using the UI from a nuget). services .AddDefaultIdentity<IdentityUser>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); With this nuget everything works as expected. Especially the loginPartial which shows the username once a user has logged in and shows the Login Button right after clicking logout. Once I

Correct return type from web API

馋奶兔 提交于 2019-12-24 01:09:18
问题 I am creating a c# .net core 2.2 web API for my next project. My question is when returning data should I return the object or IActionResult OK(returnObject) ? The reason I ask is I am using swagger and swagger studio to create my models for an Angular front end. If I return an IActionResult from the API the returned view models are not detailed in the swagger.json file so I would have to code these in the angular application. If I return whatever object is created the model is created in the

How to seed NetTopologySuite.Geometries.Point data from a Json file in ASP.Net core

て烟熏妆下的殇ゞ 提交于 2019-12-23 10:56:06
问题 I want to seed "Location" data for my user object from my seed file The c# object, where Point is a NetTopologySuite.Geometries.Point is part of my user object public class User: IdentityUser<int> { // member data here public Point Location { get; set; } // has lat/lng data points } I seed data to my db on startup by doing something like this public void SeedUsers() { if (!_userManager.Users.Any()) { var userData = System.IO.File.ReadAllText("Data/UserSeedData.json"); var users = JsonConvert

Localization file not effective rendering a Razor page in MVC ASP.NET Core 2.2

≡放荡痞女 提交于 2019-12-23 09:45:09
问题 My Razor page looks like this. @using Microsoft.AspNetCore.Mvc.Localization @inject IViewLocalizer Localizer <h1>@Localizer["Index"]</h1> ... My Startup.cs contains the following. public void ConfigureServices(IServiceCollection services) { ... services.AddLocalization(a => a.ResourcesPath = "/"); services.Configure<RequestLocalizationOptions>(a => { CultureInfo[] supportedCultures = { new CultureInfo("sv-SE"), new CultureInfo("se") }; a.DefaultRequestCulture = new RequestCulture("se"); a

How to handle model binding of Complex Type with List of interfaces and nested list of interfaces with possibly no values

北城以北 提交于 2019-12-23 04:36:32
问题 I have successfully(maybe not elegantly) created a model binder that will bind a List of Interfaces on post. Each interface has separate properties and some have a nested List of another interface. The list of interfaces get displayed correctly in the view and so do the nested list items. On post everything works, the custom model binders get called and the correct types get built. The issue that has me stuck is that if a nested List of interfaces has no items to display, on post back the