Questions tagged [asp.net-core-webapi]
Questions about ASP.NET Core web APIs and web apps that are not dependent on MVC Views or Razor Pages
8,495
questions
0
votes
0
answers
27
views
C# - ModelState is necessary in currently version of C# Web API?
I'm making a POST with the following data to my server:
{
"id": 0,
"usuarioId": 35,
"titulo": "Testing",
"descricao": "",
...
1
vote
1
answer
52
views
Invoke methods of a class that has dependency injection C# .NET Core 6.0
I have a controller in C# that invokes a class, which in turn makes HTTP requests and returns its response, according to the code sequence below:
I added the following line in Program.cs:
builder....
0
votes
0
answers
48
views
ASP.NET Core large file upload StreamContent vs MultipartFormDataContent
I know there are lots of resources and answers about uploading large files in ASP.NET Core Web API, but my question is very specific and I couldn't find any answer.
I am trying to implement the Upload ...
1
vote
1
answer
28
views
Check JWT token exists in memory cache before executing the codes in the API
I'm working on a .Net Core project with hundreds of APIs in it.
The APIs accept JWT token to authorize.
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
As JWT tokens ...
0
votes
0
answers
19
views
Web Api adding an entity data without related foreign key data
I have a database model with a one-to-many relationship. While adding data to entity, Web API creates json data with full related field. Is there a way just get one entity data in json format? List<...
0
votes
0
answers
30
views
How to read files from Desktop in Windows Service?
I have a web api application. When I run the application, I perform operations by reading the file on the desktop. It works smoothly. I am converting my application to a windows service. However, when ...
0
votes
1
answer
16
views
Troubleshooting Backend Unresponsiveness and 500 Error on Web Host in ASP.NET Core Application
I'm currently facing a perplexing issue with my ASP.NET Core 6 web application when hosted on a web server. Everything functions flawlessly on my local development server, but once the application is ...
-2
votes
1
answer
34
views
Adding Web API Authentication to existing MVC website
I have an existing ASP.NET MVC .net 7.0 web app with individual user accounts (aspnet identity), but I want to create a mobile app for the web app. I'm stuck on the authentication part, because I want ...
-4
votes
0
answers
63
views
ASP.NET API can't handle POST
I'm new to ASP.NET. I try to make a POST request to an API on my server side. I really tried to understand it myself but I can't.
Here's what I do:
Add a connection strings to mySQL -> works I can ...
0
votes
1
answer
46
views
ASP.NET Core 7 Web API inside Blazor Server project not working
I am trying to add an ASP.NET Core 7 Web API inside the Blazor Server application, but the API is not loading.
When I go to this URL: https://localhost:44322/api/GetWeatherForecast, I see the ...
0
votes
2
answers
57
views
Simple way to only return the ID of child objects
I have an ASP.NET Core Web API. I included the controller and the object that I would like to return. The problem is, this object can have a lot of children that in turn can have a lot of children. In ...
0
votes
0
answers
17
views
NSwag C# Client Not Properly Generating Azure.ETag
I have the following ASP.NET Core 7 Web API controller in C# that saves an attachment to Azure Blob Storage:
[MapToApiVersion(Constants.ApiVersions.V1)]
[HttpPost]
[ProducesResponseType(typeof(...
0
votes
1
answer
19
views
ASP.NET Core 3.1 Web API: malformed JObject: diagnose and write to log file
I have an ASP.NET Core 3.1 Web API with a POST method that accepts a Newtonsoft.Json.Linq.JObject as a [FromBody] parameter. In my code, I log the raw jobject.tostring() to a log file.
I'm having ...
0
votes
2
answers
68
views
How to set Dapper connection string in the top of the application once?
I using Dapper in my ASP.NET Core 7 Web API.
I have a lot of functions looks like that:
public async Task<int> InsertTableObject(TableObject tableObject)
{
using var connection = new ...
-1
votes
1
answer
48
views
Is there any advantage of adding async keyword in the start of an ASP.NET Core Web API method
I didn't find much on the web. I think when there is high volume of incoming requests, marking the Web API method as async can help in managing request throttling. It allows the server to handle more ...
0
votes
1
answer
31
views
ASP.NET Web API, EF Core + Identity library
I am building a hospital management system using ASP.NET Web API and EF Core.
I have these tables:
Appointments
Beds
Departments
Invoices
MedicalHistories
MedicalTests
Prescriptions
I have used ASP....
0
votes
0
answers
23
views
Why does my ASP.NET Core 6 Web API work as a standalone website, but fails as a subapplication of another website?
I've created an ASP.NET Core 6 Web API. Then I deployed it to a production Windows Server 2022 as a new website running on port HTTP 15007. After some adjustments, the application started serving ...
0
votes
1
answer
63
views
How to validate boolean configuration value while using Options Pattern in ASP .NET Core
"Foobar": {
"Baz": "invalid-boolean-value"
}
public record FoobarOptions
{
public required bool Baz { get; init; }
}
public class FoobarOptionsSetup : ...
0
votes
1
answer
84
views
Why can't I see new Controller in Swagger UI
I have an ASP.NET Core 6 Web API. I have 5 existing controllers. However, when I added a 6th controller, the same exact way, and added one route, when I run my Swagger it doesn't show.
Locally, and ...
0
votes
1
answer
53
views
Register dependency of class library which is not directly referenced in ASP.NET Core Web API
I have an ASP.NET Core Web API project with class libraries. I can register dependency of class library which are directly added as references into the project. But I am not able to find way to ...
0
votes
1
answer
16
views
Redirect from Controller with custom data to be passed
I am new to .netcore and I am migrating one of my websites to the .netcore app with React.
I have an issue with redirect:
After signup, an email is sent to the user with a link to activate their ...
0
votes
1
answer
26
views
Why am I redirected to Account/Login page when using WebApi and AspIdentityCore beside JwtBearer in dotnet 7?
I am trying to configure my ASP.NET Core 7 Web API to use ASP.NET Core Identity as the User/Role backend and use JwtBearer as the authorization method.
This is my service configuration in the Program....
0
votes
1
answer
30
views
ASP.NET Core WebAPI Serilog doesn't create the log on file
I'm creating a simple ASP.NET Core WebAPI project. I deploy this project on a real server with IIS. I changed a little bit the Program.cs to add Swagger
var builder = WebApplication.CreateBuilder(args)...
0
votes
1
answer
38
views
Error: response status is 400. The JSON value could not be converted to EmployeeAPI.Models.Tblemployee
I am trying to add Employee using Database first approach.
My tblEmployee.cs class
public partial class Tblemployee
{
public Tblemployee()
{
TblEmployeeSalaries = new HashSet<...
0
votes
1
answer
15
views
How to use RoutePrefix in sub folders in Controller folder in .net core 6 Web API Application?
I am trying to call controller action in subfolder located in main Controller folder. I changed RoutePrefix in controller and app.MapControllerRoute() in program.cs different ways. But my postman call ...
1
vote
2
answers
49
views
ASP.NET Core 7.0 Minimal Web API with Ocelot as API gateway redirects to downstream service
I have an ASP.NET Core 7.0 Minimal Web API with Ocelot as API gateway. I've uploaded it to my production server and use this configuration in ocelot.json config file:
{
"GlobalConfiguration&...
2
votes
2
answers
55
views
ASP.NET Core 6 Web API Project cannot connect SignalR via postman
I made a simple SignalR implementation following This Video. I added its dependency with builder.Services.AddSignalR(); in my Program.cs class. Then added Map into my CustomHub with this : app.MapHub&...
-1
votes
0
answers
32
views
ASP.NET Core Web API - IIS Deployment - 405 POST Method Not Allowed
I have been trying to access an ASP.NET Core Web API endpoint deployed on IIS. But POST request throws an error "405 Method not allowed".
GET requests are working fine. I have tried several ...
0
votes
0
answers
32
views
Disable auto model validation in ASP.NET Core 7 Web API?
I have a ASP.NET Core 7 Web API project with one action method. This action method accepts a model from request body like this:
public class ActionModel
{
[Required]
[MaxLength(3)]
[...
0
votes
1
answer
54
views
Azure get token wihout window prompt in c#
i'm pretty new to Azure and Microsoft Graph api, i was wondering if there was a way to get the groups of a user of a registered application. Right now i have a client_id, a client_secret, a tenant_id ...
0
votes
1
answer
31
views
Extract common functionality from controller
I am unable to decide the best way to extract some functionality being used by multiple methods of multiple controller in my project
Common functionality
var myId = httpContext?.User.Claims....
0
votes
1
answer
18
views
Requiring client certificate causing unexpected disconnect
I am trying to follow the instructions found here: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/certauth?view=aspnetcore-6.0
The goal is to get a certificate from the machine ...
0
votes
1
answer
22
views
Issue with Swagger (login page of the website is shown)
I am very new to Swagger, so this may be a silly question.
I installed Swagger on my .net core 6 web app (with React installed).
Basically all of the following
Swashbuckle.AspNetCore
Swashbuckle....
0
votes
1
answer
56
views
How to add a Controller to a ASP.NET Core Web API
I have an ASP.NET Core 8 Web API project I am building, using .NET 8 for the first time and I can't find any info on this anywhere else. I have the standard pregenerated Program.cs file here:
using ...
-2
votes
0
answers
21
views
How to capture asp.net logger logs to expose them to a frontend via API call
I am looking to create an endpoint in a asp.net 6 web project that will return the x most recent log messages.
This is so i can display them in a frontend gui.
I can seem to find an elegant solution ...
0
votes
1
answer
37
views
Ajax POST not working without parameters in the URL
Google apparently is not my friend as I have tried many of the suggestions found, yet, none have worked for me.
I have 2 simple inputs as follows:
<form id="form">
<fieldset id=&...
0
votes
1
answer
47
views
ASP.NET Core 6 Web API stream file directly from MinIO
My task is to get a .pdf file from MinIO storage and show it in application.
If file has a big size I have to wait a lot time before it downloads from MinIO and I can start to send it to UI.
This is ...
4
votes
2
answers
671
views
Error generating JWT token during ASP.NET Core Web API authorization
I have a Web API project through which I register and log in. During authorization, where I should get a token, an error appears:
An unhandled exception has occurred while executing the request. ...
0
votes
0
answers
80
views
client app connects to web api local and web api hosted in azure
I have an ASP.NET Core Web API that is hosted in azure. The Web API connects to an Azure SignalR service at startup.
Then client apps (Winforms) connects to the Web API using the Azure SignalR URL ...
0
votes
0
answers
35
views
CORS issue when calling endpoints/webapi from vue application
Ok, so I have a webapi on .netcore 3.1 on my local machine and also a separate vue3-site on the same machine. The webapi starts up on https://localhost/44347 and the vue3-site starts up on http://...
0
votes
1
answer
65
views
ASP.NET Core - Different endpoint is being called
I have following a ASP.NET Core Web Api endpoints:
[HttpGet]
public async Task<ActionResult<string>> GetApplications([FromQuery] PaginationParameters paginationParameters)
{
}
[HttpGet(&...
0
votes
1
answer
83
views
Google Authentication in ASP.NET Core Web API
In my ASP.NET Core Web API project, I want to authenticate users with google. If I put the sign in endpoint I created in a browser, I'm routed to google for authentication as expected and when I sign ...
0
votes
1
answer
29
views
How to handle the path to static files for local development and release in .NET Core web API
I have a mailService that uses static .html files as email templates for sending emails.
My current directory structure looks like this:
Infrastructure (project name)
Templates
contact....
0
votes
1
answer
68
views
when call api using ajax jQuery validation annotation not working?
I work on an ASP.NET Core MVC application I call API using ajax jQuery to prevent change URL after click submit button.
From
Resignation/RequesterIndex?filenumber=103085
to
Resignation/RequesterIndex
...
1
vote
1
answer
40
views
Upload image and Json using Javascript with axios
I uploaded a formData with an image and a JSON object using Javascript with Axios. The issue arises when I try to pass the payload to the backend and the values are never received but the image does. ...
0
votes
1
answer
65
views
Azure Event Hub With Net Core Web API
I am new with Azure event hub.My requirement is that I want to listen from one of the third-party azure event hub(I have only connection-string of third party event hub and my own storage account) ...
0
votes
1
answer
32
views
Granular Custom Model Validation in ASP.NET Web API
In an ASP.NET Web API (.NET7) project, I have a data model as follows:
public class MeetupGroup
{
public string GroupName { get; set; }
public string MeetingPlace { get; set; }
public ...
1
vote
1
answer
56
views
Username in Serilog file name in ASP.NET Core
I have an ASP.NET Core Web API. I need to add the username to the Serilog file name. My appsettings.json file looks like this:
"Serilog": {
"MinimumLevel": {
"...
0
votes
0
answers
58
views
ASP.NET Core 7 Web API: don't understand why ModelState.IsValid always returning True, even if model should be incorrect?
I've looked at other topics related to my problem, but I couldn't get it to work.
Here's my model:
public class UserRegister
{
[Required]
public string UserName { get; set; }
[Required]
...
0
votes
0
answers
40
views
Do I need Identity server od openiddict for Microservices
I am building a Blazor application that will connect to web api built sa microservices.
I am planning to use jwt for authentication AND authorization needs.
How do I authenticate and authorize jwt ...