Category Archives: .Net Core
Read token in api action
Read token in api action
Swashbuckle.AspNetCore.Annotations
Provides custom attributes that can be applied to controllers, actions and models to enrich the generated Swagger.
https://www.nuget.org/packages/Swashbuckle.AspNetCore.Annotations
model validation in .net core
using Microsoft.AspNetCore.Mvc.ModelBinding;
Use BindRequired
dynamically generate query string
namespace Microsoft.AspNetCore.WebUtilities.QueryHelpers
QueryHelpers.AddQueryString method Append the given query keys and values to the URI.
Swagger UI doesn’t support GET requests with parameters
following error message appears: “TypeError: Failed to execute ‘fetch’ on ‘Window’: Request with GET/HEAD method cannot have body”.
—Solution —
we have to use [FromQuery] parameters instead of [FromBody]
Http request works in Postman but not in C# with HttpClient
In similar situation I changed the address from http://...
 to https://...
 and that fixed the issue.
- working in postman
Not working in C# code
Now working in C# code
config Settings File According To Environment Variable .Net Core API
swagger print response or request model fields
404 not found when trying to run Api Controller action from ASP.NET core web app
When you added API controller with actions in .net core web app and if it shows 404 not found status when trying to hit that API endpoint then
Solution:
Make sure that
In Startup.cs #ConfigureServices, you have this:
services.AddControllers();
In #Configure, you have this:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
}