Removing Kestrel binding warning

This is an old question but you can resolve that conflict between launchSettings.json and appSettings.json with “externalUrlConfiguration”: true Kestrel configuration in appSettings.json: “Kestrel”: { “EndpointDefaults”: { “Protocols”: “Http1AndHttp2” }, “Endpoints”: { “HTTPS”: { “Url”: “https://localhost:4433” } } And this is launchSettings.json content: { “profiles”: { “TestApplication”: { “commandName”: “Project”, “launchBrowser”: true, “externalUrlConfiguration”: true, //add this … Read more

Asp.net core healthchecks randomly fails with TaskCanceledException or OperationCanceledException

I’ve finally found the answer. The initial reason is that when the HTTP request is aborted, then httpContext.RequestAborted CancellationToken is triggered, and it throws an exception (OperationCanceledException). I have a global exception handler in my application, and I have been converting every unhandled exception to a 500 error. Even though the client aborted the request, … Read more

Modify middleware response

.NET Core 3+ solution with proper resource handling: Replace response stream by MemoryStream to prevent its sending. Return the original stream after the response is modified: public async Task Invoke(HttpContext context) { var response = context.Response; //uncomment this line to re-read context.Request.Body stream //context.Request.EnableBuffering(); var originBody = response.Body; using var newBody = new MemoryStream(); response.Body … Read more

How to add global route prefix in asp.net core 3?

You could refer to below demo in asp.net core 3.0 to set global route prefix with api version.You could set any prefix as you like by changing services.AddControllersWithViews(o => { o.UseGeneralRoutePrefix(“api/v{version:apiVersion}”); }); 1.Create a custom MvcOptionsExtensions public static class MvcOptionsExtensions { public static void UseGeneralRoutePrefix(this MvcOptions opts, IRouteTemplateProvider routeAttribute) { opts.Conventions.Add(new RoutePrefixConvention(routeAttribute)); } public static … Read more

The specified framework ‘Microsoft.AspNetCore.App’, version ‘2.1.0’ was not found

.NET Core 2.1 SDK will be released this week. If you can’t wait until then, add this to your *.csproj <Project Sdk=”Microsoft.NET.Sdk.Web”> <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> <RestoreAdditionalProjectSources> https://dotnetfeed.blob.core.windows.net/orchestrated-release-2-1/20180515-07/final/index.json </RestoreAdditionalProjectSources> </PropertyGroup> …. </Project> And download the final SDK from: https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.1.300/dotnet-sdk-2.1.300-win-x64.exe For more details visit: https://github.com/aspnet/Home/wiki/2.1.0-Early-Access-Downloads

Access DbContext service from background task

In that case you can only rely on the servicelocater-pattern which is an anti-pattern. Also the DbContext must be instance-per-dependency (transient) rather than scoped. My suggestion is to inject IServiceScopeFactory which is a singleton and the beginn a scope in your background-worker that does the deed. using (var scope = _serviceScopeFactory.CreateScope()) { var context = … Read more

Disable verbose logging of symbol loading in vscode debug console

These logs are managed by VS Code. You can disable them in the launch.json file in the .vscode directory. You can add the following node inside any of the elements in the configurations node to disable module load messages for that configuration: “logging”: { “moduleLoad”: false } There are more options available such as exceptions … Read more

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