37,950 questions
-1
votes
2
answers
86
views
Issue with sending emails with MimeKit
I've been trying to send a 'forgot password' email for my website. I am using a template html file with replaced text to send new randomized credentials to a user. I have so far been unable to send ...
0
votes
0
answers
39
views
.NET MAUI Blazor App Generate Sitemap Error EntityRef: expecting ';'
I am trying to generate a sitemap.xml file form MAUI hybrid app in C#9
I have created a sitemap1 page which renders a static sitemap but I am getting error.
@page "/sitemap1"
@inject ...
0
votes
1
answer
201
views
Web API add a Header parameter for all Endpoints in Swagger using NSwag+Owin
I wish to add a custom header parameter in Swagger for all my endpoints in my ASP.NET Web API application running ASP.NET 4.8 using NSwag.
I have found many, many references explaining how to do this ...
48
votes
2
answers
80k
views
Using HttpClient.GetFromJsonAsync(), how to handle HttpRequestException based on HttpStatusCode without extra SendAsync calls?
System.Net.Http.Json's HttpClient extension methods such as GetFromJsonAsync() greatly simplifies the routine codes to retrieve json objects from a web API. It's a pleasure to use.
But because of the ...
156
votes
10
answers
224k
views
Web API Put Request generates an Http 405 Method Not Allowed error
Here's the call to the PUT method on my Web API - the third line in the method (I am calling the Web API from an ASP.NET MVC front end):
client.BaseAddress is http://localhost/CallCOPAPI/.
Here's ...
147
votes
7
answers
94k
views
Get the IP address of the remote host in ASP.NET Web API
In ASP.NET there is a System.Web.HttpRequest class, which contains ServerVariables property which can provide us the IP address from REMOTE_ADDR property value.
However, I could not find a similar ...
30
votes
8
answers
65k
views
Swagger UI not displaying when deploying API on IIS
Well, I'm using Swagger for my API documentation and it works perfectly in localhost, the problem begins when I host it on the IIS. For somereason it just doesn't work anymore
localhost:
https://...
91
votes
16
answers
223k
views
How to get base URL in Web API controller?
I know that I can use Url.Link() to get URL of a specific route, but how can I get Web API base URL in Web API controller?
2
votes
1
answer
206
views
API Gateway with multiple instances of a same Web API
I am creating an ASP.NET Web API gateway which needs to communicate to legacy COM component business logic written in C++. So I am creating another Web API which internally gets data from COM ...
101
votes
12
answers
222k
views
ASP.NET Web Api: The requested resource does not support http method 'GET'
I've got the following action on an ApiController:
public string Something()
{
return "value";
}
And I've configured my routes as follows:
routes.MapHttpRoute(
name: "DefaultApi",
...
86
votes
8
answers
102k
views
Remotely connect to .net core self hosted web api
I have a simple .net core web api with one action:
[Route("[action]")]
public class APIController : Controller
{
// GET api/values
[HttpGet]
public string Ping()
{
return ...
162
votes
6
answers
64k
views
DefaultInlineConstraintResolver Error in WebAPI 2
I'm using Web API 2 and I'm getting the following error when I send a POST to my API method using IIS 7.5 on my local box.
The inline constraint resolver of type 'DefaultInlineConstraintResolver' was ...
55
votes
3
answers
49k
views
How to use WebApplicationFactory in .net6 (without speakable entry point)
In ASP.NET Core 6 default template moves everything from Startup.cs into Program.cs, and uses top-level statements in Program.cs, so there's no more (speakable) Program class ether.
That looks awesome,...
137
votes
12
answers
220k
views
Multiple HttpPost method in Web API controller
I am starting to use MVC4 Web API project, I have controller with multiple HttpPost methods. The Controller looks like the following:
Controller
public class VTRoutingController : ApiController
{
...
210
votes
4
answers
249k
views
Why do we have to specify FromBody and FromUri?
Why are the FromBody and FromUri attributes needed in ASP.NET Web API`?
What are the differences between using the attributes and not using them?
133
votes
8
answers
216k
views
Download file from an ASP.NET Web API method using AngularJS
In my Angular JS project, I've an <a> anchor tag, which when clicked makes an HTTP GET request to a WebAPI method that returns a file.
Now, I want the file to be downloaded to the user once ...
0
votes
0
answers
47
views
Running ASP.NET Web API on IIS Express getting ANCM error
I am running an ASP.NET Web API application for .NET Framework 4.7.2, and when I try to run it in on my Windows 11 dev machine via IIS Express, the app is crashing with the following error:
HTTP ...
135
votes
8
answers
165k
views
'System.Net.Http.HttpContent' does not contain a definition for 'ReadAsAsync' and no extension method
I made a console app to consume a Web API I just made. The console app code does not compile. It gives me the compilation error:
'System.Net.Http.HttpContent' does not contain a definition for
'...
1
vote
1
answer
108
views
ASP.NET Web API IEnumerable.ToArray return
The ASP.NET Web API template contains a sample method:
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = ...
118
votes
13
answers
142k
views
Entity framework self referencing loop detected [duplicate]
I have a strange error. I'm experimenting with a .NET 4.5 Web API, Entity Framework and MS SQL Server. I've already created the database and set up the correct primary and foreign keys and ...
1
vote
0
answers
65
views
No sharing cache, using IMemoryCache
My api depends on some programs that are expensive to start up for each call. I am trying to inject a cache that contains the cached objects wrapping the programs so they can be reused without killing ...
0
votes
0
answers
47
views
Legacy VB.NET Hide Stack Traces For Bad Requests To Web Service
I am working on a legacy Web Forms project written in VB.net. When an authorized client makes a bad request, my application response returns a full stack trace that I want to hide.
I have a redirect ...
0
votes
1
answer
404
views
Microsoft Graph API Event.PostAsync in C# .NET Framework
I'm trying to schedule an Outlook appointment to another user's calendar using Microsoft Graph API in my ASP.NET Web API, written in C# and running on .NET 4.8.1. When I run the API code shown here, ...
0
votes
1
answer
108
views
How to restrict ASP.NET Web API from querying with different values
I have a third-party React page which makes some API calls to .NET backend. I need a way to restrict people from hacking API by changing values of the request.
When someone opens the third-party page ...
117
votes
9
answers
107k
views
Web API 2: how to return JSON with camelCased property names, on objects and their sub-objects
UPDATE
Thanks for all the answers. I am on a new project and it looks like I've finally got to the bottom of this: It looks like the following code was in fact to blame:
public static ...