Click here to Skip to main content
15,893,564 members
Everything / WebAPI2

WebAPI2

WebAPI2

Great Reads

by Vincent Maverick Durano
This article will talk about how to implement a custom wrapper for your ASP.NET Core and Web API applications for managing exceptions, providing meaningful and consistent responses to consumers.
by kannankeril
This article is an attempt at splitting out the controller layer to reduce its complexity and improve quality and maintainability of the resulting code.
by Livio Francescucci
Use a JWTToken to access a .NET Core Web API leveraging IdentityServer4 / OAuth2.

Latest Articles

by Vincent Maverick Durano
This article will talk about how to implement a custom wrapper for your ASP.NET Core and Web API applications for managing exceptions, providing meaningful and consistent responses to consumers.
by Quí Nguyễn NT
This is a demonstration of a basic example of single page Angular application and micro-service architecture on Azure.
by Aram Tchekrekjian
How to create and deploy your first ASP.NET Core Web API on IIS
by Sunny Makode
This is an introductory article about creating an Odata Rest API in collaboration with Entity Framework. We are also going to use Autofac as our IOC container. Also, Repository and Unit of Work pattern will be used for cleaner access of persistence model through our ORM (Entity Framework).

All Articles

Sort by Updated

WebAPI2 

15 Oct 2019 by #realJSOP
That's highly inefficient and requires a sh*t-ton of needless code. Just save the whole entity and be done with it. If your entities and DAL are properly designed, this shouldn't be an issue.
17 Aug 2021 by .NET- India
Hi, I am writing following code in .NET Core Web API. And project is divided in "API", "Service", "Repository". I have following request body and it is sending a mail with an attachment with a link given in "Attachment". { "To":...
2 Jul 2017 by 9000605667
I am writing one .net API for Android, Ipad apps and Web application So i am little bit confusion which is suitable for above kinds of app. So Please give me guidance which can i pick to start (i.e) Web API (or) REST. Thanks, What I have tried: So Please give me guidance which can i pick to...
29 Jun 2018 by 9000605667
after hosting the web apI applcation in godaddy. After browing in the URL i am facing the error What I have tried: Server Error in '/' Application. Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this...
18 Jul 2018 by abdul shakib
string apiUrl="http://localhost:36727/api/yourapiclass"; using (var client = new HttpClient()) { var json = JsonConvert.SerializeObject(YourModel); var stringContent = new StringContent(json, Encoding.UTF8, ...
14 Aug 2018 by abdul shakib
Web Service It is based on SOAP and return data in XML form. It support only HTTP protocol. It is not open source but can be consumed by any client that understands xml. It can be hosted only on IIS. WCF It is also based on SOAP and return data in XML form. It is the evolution of the web...
21 Mar 2017 by abhishek_singh
Hi,I have created a web api service with window authentication for Intranet users in ASP.NET Core, Authentication on service is working properly except that it accept all domain user which have valid credentials for requested machine, I just want that it validate for single domain users only,...
1 Jan 2017 by Adi_Mag
Hi All,I have read so many articles on HttpClient. In some articles, it is mentioned to create single instance of httpclient and reuse it in the entire application. But in some articles it is mentioned to create new instance of httpclient per webrequest.**// New instance per web request....
1 Jan 2017 by Adi_Mag
After lot of research and discussion. I found the best approach is to use same instance of HttpClient through out the application. Some key stuffs you need to remember while using this approach.a) Create HttpClient instance at application start and inject it through out the...
7 Dec 2016 by Afzaal Ahmad Zeeshan
Push notifications are specific to your web development framework. Because it is the server maintaining an open port for pushing the notification to client. On simple web interface, ASP.NET SignalR is enough and you can use JavaScript to handle new messages. What you need is already solved...
19 Dec 2016 by Afzaal Ahmad Zeeshan
SAML is just a standard, it entirely is in your hands to implement it, you can use any way to do so. What you need to use in this case is email address of the user, instead of your application ID and a secret token. You will have a mechanism to communicate between two or more organizations based...
22 Nov 2018 by Afzaal Ahmad Zeeshan
That process needs to be debugged, you can use the Production Testing to do that, or you can even try to connect the Visual Studio to the live environment and do a live testing of the application. That way you will understand what is being missed on the environment; perhaps a missing...
16 Feb 2019 by Afzaal Ahmad Zeeshan
As already mentioned in Solution 1, by MadMyche, you cannot simply convert your applications to an API, where API itself is a separate way or method of development of applications. An API has so many requirements, such as being stateless, headless, and cross-platform, and cross-device. APIs work...
22 Feb 2019 by Afzaal Ahmad Zeeshan
Your question itself has the answer, your task has not yet been evaluated—Result = "{Not yet computed}. You need to give it more time, and check the result later. This time won't be known to you, since it is undefined amount of time. That is because in the synchronous code you need to wait for...
16 Feb 2019 by ahmed_sa
problem How to convert that code please from mvc project to web API I work on mvc project in asp.net core 2.1 I create Employee Controller and inside it I make two function action result for create new employee and save it as following : I decided to convert above functions to web API so...
22 Mar 2019 by ahmed_sa
problem get error when make service getallemployee Conversion of type 'Promise' to type 'Employee[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.ts(2352) Conversion of type 'Promise'...
20 Feb 2019 by ahmed_sa
problem when pass id value of put(update) from postman it passed as 0 although it have value on link ? i select key from post man as contenttype application/json and this is my url https://localhost:44326/api/Employee/put?id=5 and when put breakpoint in function put and run app it hit...
27 Feb 2019 by ahmed_sa
Problem How to return EmployeeCode on angular employees component.html ? Sample data ReferenceTable Code tableName FieldName LabelText 111 Employees EmployeeId EmployeeCode Result of calling GetLabelTextForEmployee('Employees','EmployeeId') it suppose Return EmployeeCode I work...
1 Mar 2019 by ahmed_sa
problem How to assign ng model input type text on header to ngfor element ? I work on application work on angular 7 with asp.net core 2.1 on html component i have input type text and i need to assign it to ngfor element ? but cannot do that actually i need when user write or input type textbox...
16 Mar 2019 by ahmed_sa
I work on project angular 7 with asp.net web API core 2.1 data display on reference.component.ts ngoninit event variables this.RefListVal but not show on Reference.component.html my web API function [HttpGet("{tableName}")] public List GetColumnNames([FromRoute] string...
21 Mar 2019 by ahmed_sa
problem data display on strange format How to convert it to json format I make function return list of object data of column name where pass table name meaning function return column names joined with table reference but problem data display in strange format as below : the result as...
20 May 2019 by ahmed_sa
How to pass table name from first component to second component on angular 7 when click button ? I have two components and i need to pass table name from first component to second when click button on first component As you see below in first component i write table name by hand this will...
16 Jun 2021 by ahmed_sa
I work on web api asp.net core 2.2 I face issue I can't return true or false from web api compare excel as below so if excel is identical then return true else return false public bool CompareExcel(string filePath, string templatePath, out...
31 Mar 2022 by ahmed_sa
zip files not downloaded on angular 13 although zip files created and api not give error ? I work on application asp.net web api core 2.2 and angular 13 . I make web api compress files and create it first as zip files . then downloaded on my...
10 Dec 2018 by Aitzaz Ahsan
This is my statrup Class public partial class Startup { public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); ConfigureOAuth(app); WebApiConfig.Register(config); ...
25 Aug 2021 by Alexander Angelopoulos
I have a simple web api project which I am trying to call using an HttpClient (trying to fetch products from database Table). I get a result of an empty array [] although I have stored data in my Database (SQL Server). API: Model: public...
4 Aug 2017 by amey.rane86
I'm using Dapper and I have classes like this: public class Region { public Region() { Countries = new List(0); } public int RegionID { get; set; } public int RiskRank { get; set; } public string Name { get; set; } public int SiteID { get; set;...
2 Feb 2017 by AminMhmdi
hi i create asp.net web api project and use bearer token for user authorization problem is when send username=xxxx&password=xxxx&grant_type=password to http://address/Token it can generate more than one token for each user.i want to generate one token per user how can i do this??What...
28 Nov 2017 by Amr Mohammad Rashad
I need some sort of a free robust mocking server as we created part of the front-end and we are going to create the Web API later so for now we need a facility to help us mock the nonexistent service. we tried to use Apiary but it did not work for us as we expect as it sometimes removes the...
10 Dec 2017 by Amr Mohammad Rashad
Greetings, I am working on developing a library to generate a token to be used by application to access a service resource. Here is the scenario the library will accept user name and password then it should create a Jason formatted token, I was trying to use Jwt. Json token, from my point of...
12 Jan 2018 by Amr Mohammad Rashad
I am facing a CORS policy problem and I do not know how to fix it. I tried many approaches but what makes me crazy is that the service works fine on some devices and I can utilize all its resources and works a little bit on others and does not work at others while the whole devices having the...
7 Apr 2018 by Amr Mohammad Rashad
I am facing a problem that has not been resolved so far and do it over three weeks. I am supposed to create a web application that do the following: 1- Allow the user to select the search criteria from drop down list and click the export button. 2- The button click event calls an API that in...
7 Apr 2018 by Amr Mohammad Rashad
The problem has been solved all what I need is to set the Component Services -> Computers -> My Computer -> DCOM Config -> Microsoft Excel Application -> Properties -> Identity to Interactive User and decorate the class that uses the COM component, ExcelExporter, with [ComVisible(true)] attribute
16 Jul 2017 by Andy Lanng
depending of how you want to use this string, you will have to encode it for html or for url use: Server.HTMLEncode(string) Server.URLEncode(string)
15 Nov 2018 by Anele Ngqandu
Hi Guys Im doing a file upload, at first i was using fineuploader, then changed to simple ajax. The error i get is similar the "xhr:An unhandled exception was thrown by the Web Application." Now this works locally but doesn't work on the server, what am I missing on IIS configs? Kindly assist. ...
11 Jul 2017 by Ansel Castro
Develop SOLID back-ends exposed through a REST API with ODATA support and DTO mapping using Enterlib.NET.
8 Feb 2020 by Aram Tchekrekjian
How to create and deploy your first ASP.NET Core Web API on IIS
30 Nov 2019 by Ashutosh Gpt
create another class contains list of Categories public class CategoriesList { IList ListItem; } public IHttpActionResult Post(CategoriesList categories) { //... } body may something like this: ListItem : [ { id: 1, Category: 'Value1' }, { id: 2, Category: 'Value2' } ]
30 Nov 2019 by Asif Rehman
This is working fine. public IHttpActionResult Post(Categories categories) { //... } But When I change Categories to Categories[] to received multiple records from javascript client, it show null object. public IHttpActionResult Post(Categories[] categories) { //... } from postman...
16 Feb 2017 by Barcelonista Naser
SO. I am developing an application where I need to make long run Actions which proven to take more than 30k ms per request as I tested it. It does some API Calls to third party servers and return data in Json and Image formats.Throughout searching SO questions and many other blog posts...
7 Aug 2017 by Bart-Jan Brouwer
Modern design example for .NET Core MVC with RESTful service
1 Mar 2018 by benjaminemanuel13
Here is code I came up with, based on yours: static async void GoPost() { string baseUrl = "http://localhost" + "/api/Payment/AddMedicineOrder"; Dictionary parameters = new Dictionary(); parameters.Add("username",...
31 May 2017 by Bit2 Developer
I'm trying to make Web API using Asp.Net Web API 2 but getting HTTP Error 500.19 - Internal Server Error: Following is my code: What I have tried: // Api Controller public class EmployeeController : ApiController { EmployeeBusiness employeeBusiness = new EmployeeBusiness(); ...
27 Feb 2019 by Bohdan Stupak
It's hard to figure out something without a snippet of a client code calling your controller. But the most common reason is that the shape of a data you POST from a client mismatches what you expect on a server. Please double check this.
22 Mar 2019 by Bohdan Stupak
The error is pretty self-descriptive. this.http.get returns Promise which you unsuccesfully try to convert into your entities. Use this.http .get('https://localhost:44326/api/Employee') .then(res => //your logic)
2 Apr 2019 by Bohdan Stupak
No need to construct a new object with HttpRequestMessage re = new HttpRequestMessage(); use static Request instead Request.Headers.TryGetValue("username", out var test);
3 Mar 2017 by Bryian Tan
Add a [RoutePrefix("api/ServiceA")] attribute to the controller. Without that, somehow, the valid URI will be http://localhost:2280/isbn instead of http://localhost:2080/api/ServiceA/isbn[RoutePrefix("api/ServiceA")] public class ServiceAController : ApiControllerI got the same error...
31 Jan 2017 by Cathy Wun
This is the first part of Rewriting an Employee Tracker using Angular 2 and TypeScript Series.
31 Jan 2017 by Cathy Wun
This is the first part of Building an Employee Tracker using AngularJS and ASP.NET Web API Series.
6 Mar 2017 by Cathy Wun
This is the first part of building an Earnings Tracker using Angular and TypeScript Series.
26 Jun 2017 by chandubbbb
how to disable the sending of http header data in api response. like fallowing headers in asp.net web api 2 Cache-Control →no-cache Connection →close Content-Length →20 Content-Type →application/json; charset=utf-8 Date →Mon, 12 Jun 2017 10:06:04 GMT Expires →-1 Pragma →no-cache Server...
9 Sep 2019 by chandubbbb
In GPS application we receive data every 10 seconds from each device.we are displaying the device count like OffRoad, Moving, Stopped and Not working suppose no data from the device in the last 5 minutes we are marking them as Not working, we are updating device data in concurrent dictionary...
22 Dec 2017 by Charlie Andrews
Hello , I have created a webapi project. I have created an endpoint where i will receive the facebook token that the andriod developer is getting using the Facebook SDK. My query is how do i validate the token in my api ?? how do i know that this token is valid or invalid or expired ?? ...
22 Oct 2021 by CHill60
Quote: Can you check my stored procedure once ? The answer to that question is "No. We can't" - for the reasons that OriginalGriff has given you above You also state that you "already done this". So I assume that you ... 1. put a breakpoint on...
16 Jun 2021 by Chris Copeland
Most of the work is already done in the controller, you just need to return the correct IActionResult from the controller method. This tutorial page[^] has some good examples of what you can return, you just need to see which one applies here.
3 Mar 2017 by codegeekalpha
I have api controller in my project which has to retrive data from database based on ISBNWhen I am getting an error":"No HTTP resource was found that matches the request URI 'http://localhost:2280/api/ServiceA/'.","MessageDetail":"No action was found on the controller 'ServiceA' that...
4 Mar 2017 by codegeekalpha
with this URIhttp://localhost:2259/api/ServiceA/1234"where isbn=1234 isbn value is 1234 in databaseI am getting Null . While i have data in the database which should be shown hereWhat I have tried:my webapiconfig public static class WebApiConfig { public...
22 Feb 2019 by Codes DeCodes
I am calling a web service from MVC controller to post data. Both stays in same solution. My code in Web Api is: [HttpPost] public IHttpActionResult InsertUsers([FromBody]tblUserAgentSubAgentVMWithByte tblUserAgentSubAgentVM) { return Ok("Success"); } My code of...
5 Mar 2019 by Codes DeCodes
In my project, I am calling webapi services - Get action from controller of another project. My code is: using System.Net.Http; using System.Configuration; using System.Net.Http.Headers; public ActionResult Index() { ViewBag.Place = new SelectList(GetPlaces(), "ID",...
21 Aug 2020 by Codes DeCodes
I am creating prototype of application where in I am trying to send data in request header and body from C# MVC Controller and also created web api project Post action to process the request. My code goes like this:: MVC Project code to Post Request: public class HomeController :...
22 Oct 2021 by Cse Engineer
I created an update stored procedure then used that stored procedure in the put method of the web api and then consumed that api in the mvc controller. Category_Id is the primary key. What I have tried: ALTER PROCEDURE [dbo].[Update] -- Add...
4 Mar 2017 by Dave Kreskowiak
Well, you're getting null because your query WHERE condition doesn't match any records. Put a breakpoint on the using line and check the value of isbn. Chances are good its value is not what you think it is.
3 Nov 2017 by Dave Kreskowiak
500 errors mean the code on the server crashed or failed for some reason. That could be because you sent parameters it didn't expect, sent them in a format it didn't expect, values out of range, or the code on the server is poorly written and doesn't check the input parameters before trying to...
2 Jul 2017 by David_Wimbley
Web API is a framework capable of implementing/being RESTful. Rest isn't a framework its more a methodology for going about implementing your API. There are restful APIs and non-restful API's. You could create a Web API application that isn't restful, its up to you to make it restful. I...
29 Jul 2017 by David_Wimbley
So first thing, why are you making the request and expecting tex/html when web api will return json? So putting aside the formatting discrepancy, some of the issues lie with you returning entities directly from your DB via Web API. Your products class probably has a complex relationship to some...
11 Jan 2018 by David_Wimbley
Google is your friend. How I can upload image to server using web api - Google Search[^] First link from the above search [^] Upload a file to Azure Blob Storage using WebApi – Paris Polyzos' blog[^]
25 Jan 2018 by David_Wimbley
A quick google search shows that you are likely not passing JSON into the deserialize object method. c# - Unexpected character encountered while parsing value - Stack Overflow[^] Given you didn't provide much of a code sample, I'm going to say that response.Content isn't actually a string and...
5 Apr 2019 by David_Wimbley
Rather than trying to fit a square peg through a round hole, you need to refactor your code to something that will actually work and make sense. Calling controller code from an attribute doesn't make sense. Pull the IsValidUser method out of the Controller B, move it to a class called...
2 Nov 2020 by DevCodeproject1
Using Swagger (Swashbackle Package) in the .NET framework for WEB API specifications. The Swagger UI is completely different from the .NET Core's swagger UI. Is it possible to implement the Same theme in the Swagger, If yes, Could you suggest a...
16 Jul 2017 by diptyajit dey
How to Pass special character in Web Api Post method? I am save the special character like '&',''' in web api via post method. Problem is when i am pass the special character via parameter then special character remove the web api and save the value without special character. I am 1st create a...
16 Feb 2017 by F-ES Sitecore
Any solution you implement that uses IIS is going to be at the mercy of IIS shutting down your app if it uses too much memory etc. You could farm the work off to a Windows Service, maybe using MSMQ to send the requests to the service, with the service doing all the actual work, and providing a...
13 Jun 2017 by F-ES Sitecore
Yes you should put the two things in two separate projects in the same solution.
28 Nov 2017 by F-ES Sitecore
You would traditionally use interfaces to implement a dummy service your code interacts with which can later be replaced by a working one. public interface IMyService { void SomeMethod(int id); bool SomeOtherMethod(string value); } For testing you simply mock the...
5 Apr 2018 by F-ES Sitecore
Automation of Office apps like Excel isn't supported on IIS, you're simply not going to get this working. Use an alternative that is supported for asp.net like the OLEDB driver, XML SDK, or third party apps like EPPlus etc.
18 Nov 2018 by F-ES Sitecore
You've define Phonenumbers to be a List but at no point are you creating the list so para.Phonenumbers is always going to be null. You can create a new List in the constructor. public class Parameter { public int Id {get;set;} public string name {get;set;} public List...
29 Apr 2019 by F-ES Sitecore
You have a list of RegisterBindingModel objects, you then create a new object with a property of Data that points to that list and a Total property, you then try and deserialise that object back to a list. Obviously that's not going to work as the new object isn't a list of...
26 Jan 2018 by ganesh.dks
Hi, I have been trying for the past 2 days to design a simple application in C# to read from serial Port continuously and write the data as it is; say a string, to an IP:port on the machine. And later I want to read from that IP:port and use it to expose on a web service. This is my...
19 Jun 2022 by Gerardo Gamo
If you are using NET framework (any version capable of having swagger) in you web.config, 1. create a new key called IsSwaggerEnabled and set it to true ...
30 May 2019 by Gerry Schmitz
Quote: Problem is sometimes i get following exception which goes if i clean and rebuild the solution. am i missing something ? Yes. You're missing another clean and rebuild.
25 Jun 2019 by Gerry Schmitz
asp.net mvc - MVC AuthenticationManager.SignOut() is not signing out - Stack Overflow[^]
20 Feb 2018 by Gopinath0072
I created webApi global exception handler, i have to log the request parameters/JSON in the prod environment to verify the request if any exception happened, Please let me know the way to log the request message with in the ExceptionHandler . WebApiConfig public static class WebApiConfig { ...
27 Nov 2017 by H.AL
I have two solutions running on my desktop: One is a web solution using angularjs and calling the other solution which is a web API based on MVC and both are written in vb.net. Everything is working perfectly except one thing: when I tried to send a bi-dimensional I got below error: The...
23 Jul 2017 by Harmen Stoopendaal
See for solution this repo: GitHub - Harmen1969/SignalR-Postgresql-: Real time push notification using SignalR and PostgreSQL[^]
19 Jun 2022 by istudent
I using swashbuckle v 5.6.0 for api documentation and ui for test in asp.net web api2. I do not want give ability for the user to post data from swagger ui in production. How do I disable it? What I have tried: GlobalConfiguration.Configuration .EnableSwagger(c => ...
19 Dec 2016 by Jean-Claude ADIBA
Hi,In the Hub properties you have a Context property and you can access the current user who send the request like this :Int16 userId = Context.User.Identity.Name; This will work fine if you use Forms Authentification Mode to save the connected user ID in your Login method like this...
8 Oct 2018 by jRosevla
Hi everyone, I'm new to WebAPI, and this is my first time in creating one via visual studio with Entity Framework using c#. When i compile the program it doesn't give me an error. It let's me download the result instead of displaying it in json format in Internet Explorer. I'm sorry if my...
6 Apr 2017 by Kalai Selvi
I have a web api controller in my MVC project as follows public class EmployeeController : ApiController { static readonly IEmployeeRepository repository = new EmployeeRepository(); // GET api/ [HttpGet] public object Get() { var queryString =...
6 Apr 2017 by Kalai Selvi
At last i found the issue, i have done the mistake in Global.cs and WebApiConfig Updated Global.cs filed protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); ...
2 Jan 2018 by Kalirathinam
We are using Graph QL in our application(Webapi2). We wrote code for mutation and Query. We using single controller for all Graph QL app. But some time it's thrown error and service go down. On the time if call any service in Graph ql, it didn't work. Once we restart service , then only service...
25 Nov 2016 by kannankeril
This article is an attempt at splitting out the controller layer to reduce its complexity and improve quality and maintainability of the resulting code.
27 Jun 2017 by KGBRS
Hi All, I'm consuming the WebAPI from SSIS Packages so i have written the following code in the ScriptTask and my intention is it should to wait for the response (i.e. it will just call the endpoint and continue the process) var webClient = new System.Net.WebClient();...
27 Feb 2019 by kia9372
i create aweb service in asp core2.2 and send data from client (angular6). my controller in Admin area . this Startup : public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { ...
23 Jul 2017 by King Fisher
I need to implement push notification in my application, whenever a table gets updated by other user(updating some records through UI).I have been googling from the morning, but I cant able to proceed further.What I have tried:I have found some recommendations to use sqlDependency...
10 Dec 2016 by King Fisher
Application flow:consider client application is running in separate environment, web Api application is running in separate environment.here is my hub code for web api project :public class NotifyHub : Hub { public NotifyHub() { var request = new...
20 Dec 2016 by King Fisher
I have Implemented SingalR with existing web Api Application, where SignalR hub class will check the database for every few seconds and update the clients which are connected based on connection Id.here is my hub class :using System;using System.Collections.Generic;using...
4 Jan 2017 by King Fisher
I have started a timer when my hub connection is established in PushNotificationData method by clients requests.As per timer interval, it does fetch the records from the db and push to the clients. but when clients got disconnected ,this timer has to be stopped instead of pulling...
15 Aug 2018 by KingDolly
I am learning how to use RestSharp to make my web api calls. When l make a get request with Postman it returns 200 and in the body it gives me null instead of json and when l make a post request with Postman it returns a 204(no content). All suggestions are welcomed. Thanks. What I have tried:...
19 Nov 2018 by Krishna Veni
Getting the data from header IEnumerable values = new List(); this.Request.Headers.TryGetValues("Authorization", out values); but how to pass the data through header in post method in api What I have tried: how to pass the data through header in post method in api