37,950 questions
2
votes
3
answers
2k
views
How to support both json and urlencoded content-types in Web API
I want to support all 3 of the following content-types in my controller/action.
application/json
application/x-www-form-urlencoded
multipart/form-data
with this signature i can support both ...
9
votes
2
answers
12k
views
How to bind a request model in WebAPI GET request with route attribute?
GET :http://www.Example.com/Api/1/0/Book/Company/0
[Route("{UserId}/{Category}/books/{BookType}/{Page}")]
[HttpGet]
[RequestAuthorization]
public Response Get(int UserId,string Category, ...
218
votes
15
answers
223k
views
How to add/update child entities when updating a parent entity in EF
The two entities are one-to-many relationship (built by code first fluent api).
public class Parent
{
public Parent()
{
this.Children = new List<Child>();
}
public int ...
1
vote
1
answer
68
views
Empty GUID is coming to backend
Web API + NextTS
Backend
[Route("GetByPatient")]
[HttpGet("{id}")]
public async Task<ActionResult<List<Booking>>> GetByPatient(Guid id)
{
Debug.WriteLine(id);...
0
votes
0
answers
77
views
Amend ASP.NET Web API to not use Newtonsoft.Json
I am in the process of updating one of our systems to use System.Text.Json rather than Newtonsoft.Json.
I have a Data class that I have amended to use System.Text.Json. This handles calls from MVVM ...
11
votes
1
answer
3k
views
asp.net webapi UseOAuthBearerAuthentication vs UseJwtBearerAuthentication
can anybody explain me what is the difference between UseOAuthBearerAuthentication and UseJwtBearerAuthentication?
Why should i use 'UseOAuthBearerAuthentication' over 'UseJwtBearerAuthentication' or ...
3
votes
2
answers
8k
views
Access one web API controller from another
I have two web API controllers: PageController and BlogController. They contain simple crud for creating pages and blogs. Every time I create a blog, I need to create a page, but not vice versa. Whats ...
3
votes
1
answer
6k
views
How to get request url who used my webapi in asp.net?
I already write a Web API method, now I want to get a client website URL who used my API method.
I tried this line of code but I get my API URL. But I want a client URL.
var requestUrl = Request.Url;...
33
votes
6
answers
45k
views
How to resolve "TypeError: Failed to fetch" error on Blazor?
I am trying to send an HTTP request from my Blazor app to my ASP.NET Core API. I have breakpoints everywhere. The application gives an exception right after the action method on the API controller ...
3
votes
1
answer
2k
views
File Upload : ApiController
I have a file being uploaded using http post request using multipart/form-data to my class that is extending from ApiController.
In a dummy project, I am able to use:
HttpPostedFileBase hpf = ...
17
votes
3
answers
11k
views
IHttpActionResult method cannot return NotFound()
I am developing a web API for my website and have ran into a problem.
At the moment, the API is supposed to return details from the specified user.
This is my controller for accounts:
using System;
...
1
vote
1
answer
1k
views
passing json data of webapi method from controller to view
I have data in my apicontroller in following way-
public class OutletPOCController : ApiController
{
OutletPOCContext db = new OutletPOCContext();
[System.Web.Http.ActionName("GetTabText")]
...
0
votes
1
answer
302
views
HttpActionContext could not be found after I upgraded a web API
I upgraded a web API in .NET Framework 4.6 to 8.0 web API Core and got an error message from the IsAuthorized method:
The type or namespace name 'HttpActionContext' could not be found (are you ...
0
votes
1
answer
2k
views
Background job using ASP.NET Web API
Is it a good idea to use Web API to run background jobs where each job can take between 1-4 hours to complete?
Problem: sometimes I noticed that the job restarts when a worker process is recycled.
Are ...
0
votes
0
answers
41
views
How to read and modify a web.config of an ASP.NET Web API project from an ASP.NET MVC project?
There is a new requirement from the management to allow some specific list of users to update some app settings in the web.config of an ASP.NET Web API project (running on .NET 4.8 and hosted in IIS ...
2
votes
3
answers
3k
views
Difference between 'return object' and 'return Ok(object)'
(a)
var person = repository.GetPerson(id)
return person;
(b)
var person = repository.GetPerson(id)
return Ok(person);
According to the developer tools the result is the same and the status code is ...
-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
1
answer
86
views
How can I set up RabbitMQ in .NET Minimal Web API to then be able to use it in my services?
I want use AMQP connection string. I want to create a single shared connection (and channel per app lifetime to avoid resource exhaustion.
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 ...
72
votes
12
answers
73k
views
ModelState.IsValid even when it should not be?
I have API where I need to validate my user model. I choose an approach where I create different classes for Create/Edit actions to avoid mass-assignment and divide validation and actual model apart.
...
2
votes
0
answers
2k
views
ASP.NET Core API - Patch method without using JsonPatchDocument
Given the following model
public class User
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
and lets assume the following as it'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 ...
1
vote
1
answer
3k
views
Create Draft mail in Office 365 via Web API
I have a Web API backend with EF and use AzureAD to authenticate my (office365)users of the web application that is written in AngularJS.
Now I want to create a draft mail in my Web API but I don't ...
24
votes
15
answers
89k
views
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String' with .NET 5
I've been implementing IdentityServer4 to provide authorization for my React application. I have this working in my local dev environment, but am running into issues after deployed to IIS in Windows ...
13
votes
4
answers
20k
views
Getting the HttpActionExecutedContext Result values
I have created a filter which inherits the System.Web.Http.Filters.ActionFilterAttribute in the asp.net web api and would like to access some of the data inside the HttpActionExecutedContext result ...