New answers tagged asp.net-web-api
0
votes
Swagger API not refreshing the documentation
In my case I didn't have the option enabled in the VS Mac to generate XML documentations for Release mode:
simply go to the project properties and under Compiler tab, check the GENERATE XML ...
0
votes
Trouble with ActionResult in unit test can't Assert.Equal on POST return value (asp.net core mvc web api)
I wrapped @shrinith-sanil answer into an extension to make it easy to reuse with all my controllers. Thanks!
public static class ActionResultExtensions
{
/// <summary>
/// Becuase ...
0
votes
How to configure Swashbuckle to ignore property on model
Just remove { get;set; }
for example if you dont want in request to be seen Id
use it as field: public string Id;
not as property: public string Id { get; set; }
0
votes
I am getting 400 Bad Request error on Post Request
Client side code/model sample and viewmodel used at controller samples may be better for exact problem. But it seems, this is a Model Binding problem.
Are you sure jsonData is same json with POSTMAN ...
0
votes
Accepted
FastEndPoints swagger endpoint grouping name lower case issue
you have two options.
1.) the default behavior is to convert the group/tag names to title case. which can be changed like so:
.SwaggerDocument(o => o.TagCase = TagCase.None);
2.) or you can ...
0
votes
No type was found that matches the controller named 'help'
This answer does not apply directly to OPs question, but it does produce the same error
Your controller's type name needs to end with the word 'Controller', case non-sensitive.
https://learn.microsoft....
3
votes
Accepted
MemoryCache SetSize, does it limit cache entry size
So it works little bit differently from what you expect.
As stated in MS IMemoryCache docs, there's no measurement unit to handle cache size. So the developer (you) is responsible for handling all of ...
1
vote
Accepted
Data annotations not recognized by Entity Framework Core in one ASP.NET project but work properly in another
The resolution ended up being downgrading System.ComponentModel.Annotations from 5.0.0 to 4.7.0 in the problematic WebAPI project. All the attributes were recognized immediately.
-1
votes
Couchbase Bootstrap Exception: UnsupportedAddressFamilyException with CCCP
That code looks like .NET SDK for Couchbase Server and not Couchbase Lite. If that's the case, it shouldn't be tagged as couchbase-lite.
It also seems that is a very old version of the .NET SDK which ...
0
votes
Handling concurrent gift card purchases in ASP.NET Core API without causing database concurrency issues
One idea is to improve the selection process:
// 2. Attempt to get an available activation code that hasn't been
// used or expired, and isn't deleted.
var getAvailableActivationCode = await ...
0
votes
How to get only Odata.Count without value
You can use aggregate as in
?$filter=statecode eq 0&$apply=aggregate($count as Count)
This will return only the count :)
1
vote
Handling concurrent gift card purchases in ASP.NET Core API without causing database concurrency issues
The problem is transient, i.e. it should succeed on another attempt, so I would use Polly nuget package for retries.
Define policy that would retry operation on DbUpdateConcurrencyException:
private ...
0
votes
Can I provide callback from frontend (react) to backend and create API endpoint in react?
The "correct" way to do this from a HTTP standpoint is to return a HTTP 102 response from the endpoint until the ML processing is complete and the response delivered to that endpoint. ...
0
votes
How to block burp suite requests in an ASP.NET 4.8 Web API or ASP.NET Core Web API
You need read the request
userAgent = Request.Headers["User-Agent"];
if (userAgent.Contains("Mozilla/5.0"))
{
// Request is likely from a browser
}
else
{
// Request is ...
0
votes
How to Handle Cold Starts for .NET API on Kubernetes?
an alternative to reduce the code start, is to think if you can ajust the IoC to using Lazy at injections, this can save some time on code start, but your app will need more processor time on each ...
0
votes
TempData null in asp.net core
In my case I change my program.cs file and add this code :
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30); // Set your desired timeout
options....
0
votes
Serilog format context property as top level property
An ExpressionTemplate can do this:
// dotnet add package Serilog.Expressions
Log.Logger = new LoggerConfiguration()
.Enrich.WithProperty("Application", "Sample")
.WriteTo....
0
votes
Pass string array as data in jquery ajax to web api
from the question: How to pass an array as a querystring in a GET request by using JQuery AJAX
answer:
var uri = 'http://localhost:16629/api/AssassinApi/HireRocco',
hitList = ['me', 'yourself'];
$....
0
votes
Web API 2 return simple string without quotation mark when return type is IHttpActionResult
I know it's a bit late, but I had to work this out from this question and another answer.
The OP's code works if a "text/plain" formatter is added to the Web API configuration, as shown in ...
0
votes
Web Api 2.2 with odata and $expand
Credit to @TYRONEMICHAEL for providing the correct answer.
If you're using Microsoft.OData.Client, you won't alway be able to rely on expressions.
This does NOT work in version 7.21.3:
...
0
votes
Accepted
HTTPS disconnected - Kestrel
Ok, I think this came down to the service account not having permission to read the private key out of the certificate, which we fix with some magic PowerShell, which finds the certificate file and ...
0
votes
The 'Access-Control-Allow-Origin' header contains multiple values
In my case I wasn't setting the header anywhere in my code, but IIS was configured to add the header. I believe you go into IIS Manager, select your website and click HTTP Response Headers. You should ...
0
votes
Accepted
Serilog format context property as top level property
This can be achieve by create a custom JsonFormatter. When you use like
.Enrich.FromLogContext()
.WriteTo.Console(new JsonFormatter())
If you check the source code of JsonFormatter,then you ...
0
votes
CORS failed: The Same-Origin Policy disallows reading the remote resource
I found a solution, that worked for me.
First I replaced this lines:
var apiBaseUrl = builder.Configuration["ApiBaseUrl"] ?? "http://localhost:5000";
builder.Services.AddScoped(sp =...
1
vote
Accepted
If I set AccessToken and RefreshToken both (JWT) as cookies by server, They both automatically will be sent to server in each request from client
I would keep both tokens in cookies to reduce token threats in the browser. Just give the refresh cookie a path like /refresh where that is a path that you use to rewrite cookies with new tokens.
I ...
0
votes
How to add role parameter in my response body?
Update the Response Model:
public class LoginResponse
{
public string TokenType { get; set; }
public string AccessToken { get; set; }
public int ExpiresIn { get; set; }
public string ...
-1
votes
Use httpclient in .net to send multiple requests without being blocked by timeout links
The following is the solution I found later. I am replying again now, hoping to help others.
.NET has a real-time communication framework SignalR, which allows real-time communication between the ...
0
votes
Docker Debug from Visual Studio 2022 works and opens the Web API, but trying to run image from Powershell does not work, port not being listened
By default the :dev image produced by Visual Studio for debugging in the Debug configuration is not a full runnable image (see docs). That image relies on VS supplying volume mounts to use your ...
2
votes
Accepted
ASP.NET Core 8.0 SignalR: Successful Connection but No Notifications Received in Client
SOLVED
Issue
I discovered a problem while working with SignalR in my NotificationHub. The issue was that clients were connecting to the hub, but they weren't receiving any notifications, even though I ...
0
votes
Which base image to use when dockerizing an API based on .NET Framework 4.6.1?
You could start off one of the windows server images and install the specific version of msbuild from the dockerfile.
0
votes
ASP.NET webforms on .NET 4.8 with Web API : authentication issue - 401 Unauthorized error
Remove config.SuppressHostPrincipal():
This setting bypasses security for the entire application. Since web.config handles API access, it's unnecessary.
Linux Clients:
Linux clients won't have access ...
1
vote
Accepted
The instance of entity type 'User' cannot be tracked because another instance with the same key value for 'Id' is already being tracked
In my case the error occurred because multiple instances of the same entity were being tracked by the Entity Framework context, causing a conflict. The issue was related to how related data was being ...
1
vote
Accepted
StatusCode: 415, ReasonPhrase: 'Unsupported Media Type', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent
The issue you are facing stems from the fact that the ApiController convention assumes JSON by default when deserializing request bodies. Since you’re sending binary data with the application/octet-...
0
votes
Swagger UI Web Api documentation Present enums as strings?
A simple solution to add Description to the schema of enum with 2 one-liners. For this we need Schema Filter and to add schema filter to the startup, e.g.
public class EnumSchemaFilter : ISchemaFilter
...
0
votes
How can I prevent API returning response as gibberish data instead of JSON?
Because I had copied this into Postman from my browser, this included a lot of unnecessary headers and made the response come back gzipped or compressed.
By turning off Accept Encoding Header it works ...
0
votes
How to Store users detail who made the changes in blazor server
Below are some suggestions based on my opinion you could consider achieving your requirement:
1)You could create a separate database for storing audit logs. you could set up scheduled archiving ...
Top 50 recent answers are included
Related Tags
asp.net-web-api × 38096c# × 18815
asp.net × 7934
asp.net-mvc × 5801
asp.net-core × 3185
.net × 2863
asp.net-web-api2 × 2194
asp.net-mvc-4 × 2115
json × 2083
angularjs × 1894
rest × 1639
entity-framework × 1598
javascript × 1398
odata × 1349
owin × 1004
jquery × 1001
angular × 999
azure × 994
iis × 835
ajax × 792
authentication × 769
asp.net-web-api-routing × 728
json.net × 591
.net-core × 583
asp.net-identity × 551