37,950 questions
2
votes
1
answer
47
views
Validator access to database
My question is how do I need to validate fields. I have this class (request dto):
public class CompleteGoogleRegistrationRequest
{
public string IdToken { get; set; } = string.Empty;
public ...
1218
votes
29
answers
994k
views
How do I get ASP.NET Web API to return JSON instead of XML using Chrome?
Using the newer ASP.NET Web API, in Chrome I am seeing XML - how can I change it to request JSON so I can view it in the browser? I do believe it is just part of the request headers, am I correct in ...
0
votes
3
answers
141
views
Resolving a circular/recursive dependency with dependency injection
Say I have this interface:
public interface IExample
{
string GetSupportedExtension();
void DoWork(Stream input);
}
a concrete implementation like:
public class PdfExample : IExample
{
...
0
votes
0
answers
71
views
How to return data annotations error message in one string?
I'm using data annotations from System.ComponentModel.DataAnnotations in my ASP.NET project. I get an error message where you can describe the requirements such as "Name is required" and etc....
271
votes
23
answers
416k
views
Entity Framework Core: A second operation started on this context before a previous operation completed [duplicate]
I'm working on a ASP.Net Core 2.0 project using Entity Framework Core
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
<PackageReference ...
306
votes
11
answers
203k
views
Exposing localhost to the internet via tunneling (using ngrok): HTTP error 400: bad request; invalid hostname [closed]
From previous versions of the question, there is this: Browse website with ip address rather than localhost, which outlines pretty much what I've done so far...I've got the local IP working. Then I ...
0
votes
1
answer
108
views
Cannot see my API call on frontend console?
fetch('https://localhost:7077/api/test/users')
.then(res => res.json())
.then(data => console.log('Users:', data))
.catch(err => console.error('Error:', err));
Error:
Promise {<...
208
votes
34
answers
364k
views
The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider" could not be located
It's a WebApi project using VS2015.
Step to reproduce:
Create an empty WebApi project
Change Build output path from "bin\" to "bin\Debug\"
Run
Everything is working perfectly until I changed Build ...
470
votes
15
answers
778k
views
Best practice to return errors in ASP.NET Web API [closed]
I have concerns on the way that we returns errors to client.
Do we return error immediately by throwing HttpResponseException when we get an error:
public void Post(Customer customer)
{
if (...
682
votes
18
answers
530k
views
Does IMDB provide an API? [closed]
I recently found a movie organizer application which fetches its data from the IMDB database.
Does IMDB provide an API for this, or any third party APIs available?
278
votes
20
answers
478k
views
HTTP Error 500.19 and error code : 0x80070021
I have a simple webAPI build by Visual Studio 2013. It works well when I run it from VS13 but when I copy the project in local IIS it gives me the following error.
HTTP Error 500.19 - Internal Server ...
103
votes
25
answers
171k
views
How to configure Swashbuckle to ignore property on model
I'm using Swashbuckle to generate swagger documentation\UI for a webapi2 project. Our models are shared with some legacy interfaces so there are a couple of properties I want to ignore on the models. ...
360
votes
7
answers
443k
views
JWT authentication for ASP.NET Web API
I'm trying to support JWT bearer token (JSON Web Token) in my web API application and I'm getting lost.
I see support for .NET Core and for OWIN applications.
I'm currently hosting my application in ...
688
votes
4
answers
292k
views
Best practice to call ConfigureAwait for all server-side code
When you have server-side code (i.e. some ApiController) and your functions are asynchronous - so they return Task<SomeObject> - is it considered best practice that any time you await functions ...
1
vote
1
answer
93
views
.NET - TestContainers many instance PostgreSql conflict
I'm writing integration tests in my .NET Web API. I'm using XUnit for this. I am using factory and collection. And everything works as expected. I run factory there I have used PostgreSql database ...
410
votes
9
answers
325k
views
Difference between ApiController and Controller in ASP.NET MVC
I've been playing around with ASP.NET MVC 4 beta and I see two types of controllers now: ApiController and Controller.
I'm little confused at what situations I can choose a particular controller.
...
345
votes
7
answers
349k
views
How do I set a cookie on HttpClient's HttpRequestMessage
I am trying to use the web api's HttpClient to do a post to an endpoint that requires login in the form of an HTTP cookie that identifies an account (this is only something that is #ifdef'ed out of ...
205
votes
28
answers
437k
views
Could not load file or assembly 'System.Web.Http 4.0.0 after update from 2012 to 2013
I did the upgrade according to.
http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2
I get the error. Does any one else got this ...
275
votes
18
answers
244k
views
Multiple actions were found that match the request in Web Api
I keep getting this error when I try to have 2 "Get" methods
Multiple actions were found that match the request: webapi
I been looking around at the other similar questions about this on stack but ...
372
votes
9
answers
259k
views
Where is HttpContent.ReadAsAsync?
I see in tons of examples on the web using the new HttpClient object (as part of the new Web API) that there should be HttpContent.ReadAsAsync<T> method. However, MSDN doesn't mention this ...
1
vote
1
answer
106
views
T5ManagerAPI fails to initialize after .NET 8 publish (works fine locally)
I'm building a .NET 8 Web API that connects to MetaTrader 5 using the MT5 Manager API.
Everything works perfectly when running locally from Visual Studio.
However, after publishing and deploying the ...
185
votes
16
answers
389k
views
Postman: sending nested JSON object
I am using ASP.NET Web API: http://xyzdomain.com:16845/api/returns/returns
How do I send a POST request to the endpoint using Postman Chrome extension, given Items is a collection:
[
{
"Items":...
0
votes
0
answers
70
views
ASP.NET Web API - Model binder validation property name
I have a basic ASP.NET Web API project. When I send a request, the serialization is done using System.Text.Json. However, when I send a non-valid json, for example text instead of number, it returns a ...
200
votes
14
answers
436k
views
Make Https call using HttpClient
I have been using HttpClient for making WebApi calls using C#. Seems neat & fast way compared to WebClient. However I am stuck up while making Https calls.
How can I make below code to make Https ...
214
votes
9
answers
293k
views
Specifying a custom DateTime format when serializing with Json.Net
I am developing an API to expose some data using ASP.NET Web API.
In one of the API, the client wants us to expose the date in yyyy-MM-dd format. I don't want to change the global settings (e.g. ...