How to add method description in Swagger UI in WebAPI Application

This is well documented in the project: https://github.com/domaindrivendev/Swashbuckle.AspNetCore#include-descriptions-from-xml-comments Include Descriptions from XML Comments To enhance the generated docs with human-friendly descriptions, you can annotate controller actions and models with Xml Comments and configure Swashbuckle to incorporate those comments into the outputted Swagger JSON: 1 – Open the Properties dialog for your project, click the “Build” … Read more

Should I always add CancellationToken to my controller actions?

Should I always add CancellationToken to my controller actions? No. You should not always. Using CancellationTokens in ASP.NET Core MVC controllers https://andrewlock.net/using-cancellationtokens-in-asp-net-core-mvc-controllers/ Whether this is correct behaviour will depend on your app. If the request modifies state, then you may not want to halt execution mid-way through a method. On the other hand, if the … Read more

JWT Authentication and Swagger with .NET Core 3.0

After some research, I eventually found the answer here Before seeing this page, I knew that I should use AddSecurityRequirement after AddSecurityDefinition because of many samples, but it was a problem that the function parameters have changed on .NET Core 3.0. By the way, the final answer is as below: services.AddSwaggerGen(c => { c.SwaggerDoc(“v1”, new … Read more

Mock IHttpContextAccessor in Unit Tests

You can use the DefaultHttpContext as a backing for the IHttpContextAccessor.HttpContext. Saves you having to set-up too many things Next you cannot use It.IsAny<string>() as a Returns result. They were meant to be used in the set up expressions alone. Check the refactor [Fact] public async Task test_GetBookByBookId() { //Arrange //Mock IHttpContextAccessor var mockHttpContextAccessor = … Read more

How do I get current user in .NET Core Web API (from JWT Token)

The accepted answer did not work for me. I’m not sure if that’s caused by me using .NET Core 2.0 or by something else, but it looks like the framework maps the Subject Claim to a NameIdentifier claim. So, the following worked for me: string userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; Note that this assumes the Subject sub … Read more

Creating a proxy to another web api with Asp.net core

If anyone is interested, I took the Microsoft.AspNetCore.Proxy code and made it a little better with middleware. Check it out here: https://github.com/twitchax/AspNetCore.Proxy. NuGet here: https://www.nuget.org/packages/AspNetCore.Proxy/. Microsoft archived the other one mentioned in this post, and I plan on responding to any issues on this project. Basically, it makes reverse proxying another web server a lot … Read more

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