Questions tagged [asp.net-web-api]

13718 questions
1

votes
1

answer
29

Views

can't connect to method in the controller

I'm using asp.net web api. I'm trying to have a positive response from the server, however program is not seeing one of the methods in the controller. It goes into the controller constructor, but not further. The response is Status Code 404, Reason Phrase: Not Found. I understand that it can be a...
Alice
0

votes
1

answer
13

Views

Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only support

I am going to receive an object like the following: BOI BOI SBH SBH BOI 2234682 bsnl 1116 SCIENTIST 'E' B Rama Krishna Reddy 51910 false A- N 01-07-1958 00:00:00 B Pulla Reddy(Late) M M and here is my interface export interface IEmployeePersonalInformation { EmployeeCode: string; EmployeeName: strin...
rammi
0

votes
0

answer
5

Views

How to format XML in Post body for as asp.net WebAPI POST route

I Have an asp.net WebAPI RESTful service, where I have a POST endpoint for GPS positions. The server controller has the following route.. public HttpResponseMessage PostGpsPositions(GpsPositionsModel positions) The body classes are as follows public class GpsPositionsModel { [Required] public int S...
peterc
1

votes
3

answer
48

Views

How to remove specific JSON property from JSON string

I'm setting up audit log for web api. Here i would like to remove password property from json string because of security reason. I don't want to log login password for login API. Json/Request Payload: {'code':'medics1','username':'admin','password':'password'} I tried with below code: var payload =...
Nayan Rudani
1

votes
1

answer
47

Views

Timer like functionality for web api

Is there a way to have a timer like functionality so I can call the web api to get the updated records every second? for example I have this web api [httpget] public IList GetUpdates() { return details; } I need to call this api every second so I can display the updated records on my web page.
MMb
0

votes
1

answer
18

Views

How to add “code” in Response Body of IHttpActionResult return BadRequest(Message)

I am returning BadRequest('Failed Invalid Product Id'), which returns me Response code 400 and Response Body { 'error': { 'code': '', 'message': 'Failed Invalid Product Id' } } How can I send the Response code 400 in the Response Body so I get Response Body Like: { 'error': { 'code': 400, 'message'...
Sushrut Bhosale
0

votes
0

answer
3

Views

How to consume a web api with oauth2 authorization using ASP.net MVC?

I've been looking for ways of how to consume a web api with an oauth2 authorization using ASP.Net MVC. Any suggestions? I have already tried sending a request to the web api and recieve a response. But I'm having a hard time when it involves Oauth2 authorization because i don't know how to send head...
ikey
0

votes
2

answer
15

Views

how to protect my Web API Basic Authentication credentials

I've just started implementing Authentication in my Web API. I want to start with Basic Authentication I learned that i've to pass Username and Password in every request. So, lets say i'm doing some Admin task and making API call for same like this: $.ajax({ url: host + 'homework/delete/' + $(this...
donstack
1

votes
1

answer
4.3k

Views

CurrentPrincipal/User is empty in Web API service

I may be missing something obvious here. I'm new to both MVC and Web API, so I'm working on keeping my head above water. I have an MVC application that interfaces with a Web API service. Authentication will be handled by a login service developed internally. When working, the MVC client should ch...
Yoc
0

votes
0

answer
25

Views

How to keep DbContext in Connected state with Web API

Since Web APIs are stateless when you have EF Core backend after any request the DbContext would be disconnected. Therefore we have made QueryTracking as NoTracking since default behavior TrackAll doesn't give any benefit since its a web application DbContext.ChangeTracker.QueryTrackingBehavior = Q...
Nipuna
1

votes
1

answer
161

Views

ASP MVC WebApi call returns an error 'not found'

' The resource cannot be found. body {font-family:'Verdana';font-weight:normal;font-size: .7em;color:black;} p {font-family:'Verdana';font-weight:normal;color:black;margin-top: -5px} b {font-family:'Verdana';font-weight:bold;color:black;margin-top: -5px} H1 { font-family:'Verdana';font-weight:norma...
1

votes
2

answer
54

Views

HttpActionContext unique request identifier

I am running some load tests on my Web API application, and am trying to find a way to identify each request as it comes in to the methods OnActionExecuted and OnActionExecuting My question is, within the objects HttpActionExecutedContext and HttpActionContext is there some kind of unique identifier...
Alex
1

votes
2

answer
91

Views

Calling a synchronous method in an async fashion?

I'm developing an ASP.NET MVC WebApi project and one of the methods needs to make a LDAP search. The amount of information the search retrieves from the LDAP server ensures the call takes at least 7 seconds to complete. The call, as it uses the System.DirectoryServices.Protocols classes and methods,...
Léster
1

votes
2

answer
57

Views

Linq Include and Where conditions on Parent-child relation

This is my scenerio: I have model of Company: public class Company { [Key] public int Id { get; set; } public string Name { get; set; } public virtual List Products { get; set; } public virtual List Employees { get; set; } } and API endpoint that looks like this: //GET: api/company/Profile?id...
michasaucer
1

votes
1

answer
66

Views

Choosing not to await async function in action in ASP.NET Core WebAPI controller

The scenario is the following: Backend: Asp.NET Core WebAPI 2.2 Frontend: iOS and Android which consumes the API I have a function allowing the user to send messages to other users. The sending of a message is done in an asynchronous action: public async Task CreateMessage This action does the foll...
solojuve1897
1

votes
1

answer
86

Views

Circular dependency in ASP.NET Core

For school we have to write our own WebApi using the .NET Entity Core Framework. I've written my api but when I tried to use it in swagger, it always returned a HTTP 500 error: internal server error. I downloaded Fiddler to start debugging and came across a circular dependency error in my repository...
Mout Pessemier
0

votes
0

answer
4

Views

how to serialize entities that have a one to many relationship and a pagination in entity framework?

I have a two Model for two table having foreign key relationship. I have to get record from both table in single request. The structure of model is as follows:- EmployeeRecord.cs public partial class EmployeeRecord { [System.Diagnostics.CodeAnalysis.SuppressMessage('Microsoft.Usage', 'CA2214:DoNotCa...
Amardeep Gupta
1

votes
3

answer
44

Views

Newtonsoft JSON DefaultSettings per Assembly

In order to automatically trim all input strings and remove new lines, I developed an implementation of JsonConverter and registered it in Startup with JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Converters = new List { new StringTrimmer() } }; This works, but the string trimme...
Dave
0

votes
1

answer
54

Views

.NET Core and JSON Web Tokens, still need Owin?

first time doing this in .net core, I've set up JWT auth / ASP Identity database using these tutorials, both of which are quite good: https://www.youtube.com/watch?v=yH4GhmTPf68 https://www.youtube.com/watch?v=vEU9SDmIvVY However, when I set this up a few years ago, I used OWin. I'm having trouble f...
AS2012
3

votes
1

answer
73

Views

Service fabric hosted Asp.net WebApi Container application : 403 - Forbidden : Access is denied. on local cluster

I'm trying to do a lift and shift of a Asp.net MVC application . I've containarized my Asp.Net WebApi application and deployed it AzureContainerRegistry and i'm referencing the container in a service fabric application. My ServiceManifest looks like this bookingacr.azurecr.io/bookingapi And the App...
Arshad Badar Khan
0

votes
1

answer
11

Views

IIS Rewrite based on query string value

I am new to IIS Rewrite, Need someone to assist me, I am in a scenario to redirect to another domain based on querystring value. Ex: Request: http://localhost:50743/api/Values?stdId=1000&stdName='Test' http://localhost:50752/api/Values?stdId=1001&stdName='Test1' http://localhost:50753/api/Values?std...
Vicky S
1

votes
0

answer
130

Views

ASP.NET Web API and IdentityServer issue with CORS

I had an MVC controller which was doing logout and it was working fine. We decided to migrate from MVC to Web API and translated all the code. Now, on logout action I'm getting response error like CORS request made for path: path-to-my-identity-server/login from origin: localhost:port but rejecte...
anatol
1

votes
0

answer
88

Views

SignalR setup when separating out data access layer

Current setup has a single webapi with controllers, services, SignalR Hubs/server, data entity models and view models (say Project.Main). The thought is to create a separate project (Project.Data - webapi) for Data entity model, view models and services. Project.Main would reference Project.Data to...
Shyamal Parikh
1

votes
1

answer
259

Views

What's the best way to implement roles in a multi-tenant .net project?

My application is .NET 4.7 Web Api with Entity Framework 6. This is for a software as a service tool I am building. In my application there is a many to many relationship between AspNetUser and Company. A user can have many companies, and a company can have many users. A user needs to have a diffe...
Suren
1

votes
0

answer
787

Views

How to use dependency injection in ActionFilter Web API?

I am trying to get work with dependency injection into the action filter, but it seems not working I've registered the type in UnityConfig public static void RegisterComponents(IUnityContainer container) { GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container)...
M005
1

votes
1

answer
507

Views

Combine ASP.NET MVC and Web API projects using identity

I am new to ASP.NET and I have to create an ASP.NET MVC project using the identity framework for authentication and authorization, but the access to the database (SQL Server) must be done in an independent web service project so I created a Web API project with also identity containing all services...
sam
1

votes
0

answer
129

Views

How to perform a LINQ join on IQueryable<T> in odata controller

I have a WebAPI method which uses the OData Query Options to return data to the client. The entity has cityid and I want cityname from another entity using joins. I have tried using below Api method, which is incomplete. Entity1:- public partial class UU_DeliveryCharges { public int DeliveryChargeId...
Sunil Chaudhary
1

votes
0

answer
328

Views

Excel download from Asp.Net Web API using Axios post method

I have an action which returns excel file. [HttpPost] public async Task Export([FromBody] QueryParameters qp) { var stream = _service.GetExcel(qp); var exportFileName = 'MyExcel'; return File(stream, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', exportFileName)...
Parashuram
1

votes
1

answer
37

Views

SignalR methods in WebApi controller not called in specific setup

Well, I have a signalR hub: public class ReportHub : Hub { private static IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext(); public void SendMessage(string text) { Clients.All.sendMessage(text); } public static void ServerSendMessage(string text) { hubContext.Clients.All.sendMess...
udovichenko
1

votes
0

answer
16

Views

WebAPI, no Post

WebAPI, I'm getting a HTTP 500 error. The alerts that I put in are firing correctly. But I put a breakpoint in the Post method in ProductsController.cs. It didn't stop at the breakpoint which seems to indicate that the routing wasn't right. My intention is to have the Post method add the new row to...
DRL
1

votes
1

answer
749

Views

How to return a file using byte [] with web Api?

I trying export file with web Api. this is my client code : exportLicense(licenseIds) { return this.$http({ method: 'POST', contentType: 'application/zip', url: this.application.resolveWebApiService('Licenses', 'ExportLicenses'), data: licenseIds }); } ExportLicenses method from my backend side(my...
eagle
1

votes
1

answer
169

Views

Interrupted downloads when downloading a file from Web Api (remote host closed error 0x800704CD)

I have read near 20 other posts about this particular error, but most seem to be issues with the code calling Response.Close or similar, which is not our case. I understand that this particular error means that typically a user browsed away from the web page or cancelled the request midway, but in o...
David Anderson
1

votes
0

answer
445

Views

Unable to capture Access token from Azure using this.adalService.acquireToken

I am using ng2-adal for Azure AD authentication. I have created 2 projects, one is Angular 2 and WebAPI. Using ng2-adal, I am able authenticate user and got the Web App access token, but to get access token of Web API, I am using below code public getToken(): any { debugger; return this.adalServic...
Raj4MS
1

votes
2

answer
3.5k

Views

Angular SignalR HubConnection gives 'Protocol error: Unknown transport.'

I have an Owin-selfhosted API running on http://localhost:8090/. I created a signalR hub with the following code: app.UseCors(CorsOptions.AllowAll); //Inside Startup.cs app.MapSignalR(); //Inside Startup.cs //Inside own class file public class SensorHub: Hub { public void Send(string message) { Cons...
G Versluis
1

votes
2

answer
124

Views

EF Code First - How to Deploy to Azure

I've been struggling with this all day. I can't make my WebApi to access my database. I'm using the Code First approach with Entity Framework. When I'm deploying, a new connection string is added to web.config. And this raises an exception: This is what I've got in my web.config (locally): And thi...
RottenCheese
1

votes
1

answer
128

Views

Restrict Asp.Net Web API numeric value bindings to base 10

In an Asp.Net Web API controller I have, there is a PostAsync method that bind the request JSON body to a model class. E.g.: public class EmployeesController : ApiController { ... public async Task PostAsync([FromBody] Employee employee) { ... } ... } The Employee model class contains a numeric prop...
Liroy Alima
1

votes
1

answer
233

Views

Structuremap - dependency injection - EF Core DBContext lifetime per request

Has anyone had any luck setting up an EF Core DBContext with Structuremap 'correctly' (what is correctly?) DBContext needs to be a singleton across the lifetime of the request. I understand that the default lifecycle is Transient. I understand that that will get a nested container, which effectively...
jenson-button-event
1

votes
0

answer
96

Views

Arduino POST long JSON data

I want to send dynamically sized (long) JSON data to a web API over an Ethernet module. Before sending the data, I have to send HTTP headers. My JSON data size is very big and I don't want to store this data in memory only to calculate the length of the data to send the Content-Length HTTP header. B...
Onur Tekir
1

votes
0

answer
195

Views

multipart/form-data ASP.NET Web API 2 - cannot bind data with BindModel (ViewModel) in action

I added this line to my WebApiConfig config.Formatters.XmlFormatter.SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue('multipart/form-data')); (From my research I found that this is the only way to receive data and file at the same time, PS: Can I send JSON data and file data...
john
1

votes
1

answer
669

Views

How to upload image to server using web api?

I am at learning phase of web api and I want to upload image to server using web api in mvc dot net. I have tried much but not getting solution. In controller I have done this. string img = username + '_' + labTestId + fb; var element2 = image; MemoryStream ms = new MemoryStream(Convert.FromBase64St...
SoftwareStudent

View additional questions