Set dummy IP address in integration test with Asp.Net Core TestServer

You can write middleware to set custom IP Address since this property is writable: public class FakeRemoteIpAddressMiddleware { private readonly RequestDelegate next; private readonly IPAddress fakeIpAddress = IPAddress.Parse(“127.168.1.32”); public FakeRemoteIpAddressMiddleware(RequestDelegate next) { this.next = next; } public async Task Invoke(HttpContext httpContext) { httpContext.Connection.RemoteIpAddress = fakeIpAddress; await this.next(httpContext); } } Then you can create StartupStub class … Read more

How can I use DateOnly/TimeOnly query parameters in ASP.NET Core 6?

Turns out, there are two solutions: Custom ModelBinder + Swagger configuration Custom TypeConverter (Swagger will automatically see it, and update UI accordingly) I went with TypeConverter, and everything worked! Since .Net team are not planning to add full support for DateOnly/TimeOnly in .Net 6, I’ve decided to create a NuGet to do so: https://www.nuget.org/packages/DateOnlyTimeOnly.AspNet (source … Read more

Unable to resolve service for type ‘Swashbuckle.AspNetCore.Swagger.ISwaggerProvider’

A call to services.AddSwaggerGen(); appears to be missing in the ConfigureServices. public static IServiceCollection AddSwaggerGen( this IServiceCollection services, Action<SwaggerGenOptions> setupAction = null) { // Add Mvc convention to ensure ApiExplorer is enabled for all actions services.Configure<MvcOptions>(c => c.Conventions.Add(new SwaggerApplicationConvention())); // Register generator and it’s dependencies services.AddTransient<ISwaggerProvider, SwaggerGenerator>(); services.AddTransient<ISchemaGenerator, SchemaGenerator>(); services.AddTransient<IApiModelResolver, JsonApiModelResolver>(); // Register custom configurators … Read more

Registering a new DelegatingHandler in ASP.NET Core Web API

As already mentioned in previous comment, look into Writing your own middleware Your ApiKeyHandler can be converted into a middleware class that takes in the next RequestDelegate in its constructor and supports an Invoke method as shown: using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; namespace MyMiddlewareNamespace { public class ApiKeyMiddleware { private readonly RequestDelegate _next; private … Read more

What is SetCompatibilityVersion inside of the startup class of asp.net Web API core project

When you call the AddMvc method, several components are registered with certain options. You call one method and the whole mvc framework is wired up. However, if the mvc team in the future decides to change a default value, or decides that a component is no longer to be registered by default, or changes an … Read more

Failed to determine the https port for redirect in Docker

The two warnings are totally unrelated. For the DataProtection warning, I recommend following the guidance presented here on the official ASP.Net Core documents. If you care to dig in deeper as to the relevant source code and decision, you can see this relevant ASP.Net GitHub PR. For the https redirection warning, I recommend simply removing … Read more

Enum type no longer working in .Net core 3.0 FromBody request object

For those who are looking for a snippet when using System.Text.Json public void ConfigureServices(IServiceCollection services) { services.AddControllers().AddJsonOptions(opt => { opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); } .NET 6 / Top-level statement style using System.Text.Json.Serialization; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers() //convert strings to enums .AddJsonOptions(options => options.JsonSerializerOptions.Converters .Add(new JsonStringEnumConverter()));

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