.net core 3 not having ReferenceLoopHandling in AddJsonOptions

As part of the work to improve the ASP.NET Core shared framework, Json.NET has been removed from the ASP.NET Core shared framework. Your app may require this reference if it uses Newtonsoft.Json-specific feature such as JsonPatch or converters or if it formats Newtonsoft.Json-specific types. To use Json.NET in an ASP.NET Core 3.0 project: Add a … Read more

ASP.Net Core 1 Logging Error – The description for Event ID xxxx from source Application cannot be found

I have not been able to use the loggerFactory.AddEventLog() in .Net Core 2.0. As the Microsoft.Extensions.Logger.EventLog only lives in .net 4.5.1 although the Nuget package is available for 2.0.0 here , so looks like it needs to be ported to Core. but maybe this will work for you. Add your CustomEventIds public static class CustomEventIds … Read more

Is it possible to combine [FromRoute] and [FromBody] in ASP.NET Core?

It’s doable by a custom model binder as mentioned in the comment. Here is a few code snippets to wire everything up, with the example you can send a http request with the following JSON body to an API /api/cats?From=james&Days=20 { “Name”:””, “EyeColor”:”Red” } A few classes, you can find them here as well: https://github.com/atwayne/so-51316269 … Read more

#if DEBUG vs if (env.IsDevelopment())

Preprocessor directives are conditionally compiled… Which means that something like this: #if DEBUG //Do something #endif Will only be compiled and checked if the DEBUG symbol is defined (it is defined when the build is set to DEBUG). Additionally, in the IDE the code between the preprocessor symbols will appear greyed out. This code: if … Read more

.NET Core Cookie Authentication SignInAsync not working

as of .net 2.x, if you’re using cookie auth, ensure you include the authenticationScheme and specify name and role claim types, the identity and auth properties. //You should specify the ‘types’ of the claims which acts as ‘name’ and ‘role’, furthermore, you should have claims with those types in your claimsIdentity like that var identity … Read more

What does “Challenge” term stand for?

A ChallengeResult is an ActionResult that when executed, challenges the given authentication schemes’ handler. Or if none is specified, the default challenge scheme’s handler. Source code for ChallengeResult So for example, you can do: return Challenge(JwtBearerDefaults.AuthenticationScheme); //Can specify multiple schemes + parameters This will challenge the JWT Bearer authentication handler. In this handler’s case, it … Read more

Mark strings as non-nullable in ASP.NET Core 3.0 Swagger

You can now use nullable reference types to mark strings as optional or required: Enable nullable reference types for your project/solution Mark strings in Dtos as nullable: public class ExampleDto { [StringLength(64, MinimumLength = 4)] public string RequiredString { get; set; } [StringLength(200)] public string? OptionalString { get; set; } } Enable Swagger support in … Read more

How to mock IOptionsSnapshot instance for testing

You should be able to mock up the interface and create an instance of the options class for the test. As I am unaware of the nested classes for the options class I am making a broad assumption. Documentation: IOptionsSnapshot //Arrange //Instantiate options and nested classes //making assumptions here about nested types var options = … Read more

Is it possible to redirect request from middleware in .net core

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Antiforgery; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; namespace Test.Middleware { public class TestMiddleware { private readonly RequestDelegate _next; public TestMiddleware(RequestDelegate next) { _next = next; } public async Task InvokeAsync(HttpContext httpContext, AppDbContext dataContext, UserManager<User> userManager, IAntiforgery antiforgery) { // Redirect to login … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)