Click here to Skip to main content
15,892,927 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 Title

WebAPI2 

14 Feb 2020 by Pascualito
Hi, Technologies : ASP.Net WebForms or MVC, WebAPI I need to create "something" to send notifications, kind of reminders, for instance to remind a person his appointment with a doctor. The dates to send the notifications are saved in a DB The...
14 Feb 2020 by Richard Deeming
If it has to be in ASP.NET, there are various tools you can use to schedule background jobs: How to run Background Tasks in ASP.NET - Scott Hanselman[^] However, I would be inclined to create a small console application to scan the database and...
14 Feb 2020 by Pascualito
Hi I haven't read the first option yet, but I agree with you about the second solution. It's seems to be a very simple solution. Thanks a lot Richard!! Pascualito
14 Feb 2020 by MadMyche
If you are using SQL Server, another option would be to utilize SQL Agent as well as Database Mail How To Send Mail Using SQL Server: Part 1[^]
7 Aug 2017 by Bart-Jan Brouwer
Modern design example for .NET Core MVC with RESTful service
27 Dec 2018 by tranthanhtu.vn
[TinyERP: SPA for Enterprise Application]Manage Staffs - Part 2
1 Aug 2017 by Sebastiaan Meijerink
Hi, In our product setup we have some separate webservices that are hosted as a single site. The webservices come from separate .NET projects. This is so that all webservices can be maintained as separate products with separate release versions. They are installed together within a single...
1 Aug 2017 by Thomas Nielsen - getCore
For what you're trying to do, connecting from one web service to another service without using passthrough authentication it seems you'll need to authenticate usage of that service in another way. So there's always indigo or WCF as it came to be called. Windows Communication Foundation is the...
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...
20 Jun 2018 by Member 12910307
here i am using angularjs and webapi. in the entering fields i have one dropdown for channels, one text for from amount one, another dropdown for conditions(=), one text box for to amount, one more text box for fee amount. The scenario is when i select one channel and enterin from value and...
15 Dec 2017 by O.Nasri
ASP.NET Core 2.0 & Angular 4: through this tutorial, you will learn how to build from scratch a web application for vehicles management
4 Jun 2020 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.
11 Jun 2017 by Livio Francescucci
Use a JWTToken to access a .NET Core Web API leveraging IdentityServer4 / OAuth2.
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...
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.
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
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.
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...
30 May 2019 by titu-1670319
Hi I am using unity container for depency injection by attributes using following code container.RegisterTypes( AllClasses.FromLoadedAssemblies() .Where(t => t.GetCustomAttributes(true).Any()), ...
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.
6 Nov 2017 by walid youssef
I have the following table: Cans Id: int HospitalId: (Foreign Key) int operDt: DateTime I need to calculate the total number of cans rows grouped by hospitalId to get a similar result without Id screenshot[^] What I have tried: The repository : public Task...
6 Nov 2017 by Richard Deeming
You're returning a Task, rather than the results of that Task. You're also disposing of the DbContext before the Task has completed. (There's also a missing "t" in the action parameter name, but I'm not sure whether that's just a typo in your question.) Try something like this: public async...
19 Nov 2018 by wizklaus
public class Parameter { public int Id {get;set;} public string name {get;set;} public List Phonenumbers{get;set} } public class Phonenumber { public string number1 {get;set;} public string number2 {get;set;} public string number3 {get;set;} } public ActionResult...
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...
19 Nov 2018 by Vincent Maverick Durano
Your code doesn't make sense because your Phonenumbers property of type List will always have an empty value, thus it will never go inside your foreach-loop even if you initialize your List. Quote: Please how can i pass values to this list You don't need a loop to assign values...
8 May 2018 by Pascualito
Should I use Async or simply Sync methods in my WebApi aplication? I use mvc5 and EF 6. The operations are mainly CRUDs and listing ( select against the database ) and the DB queries are running quite fast. The system is used by about 1000 concurrents users. Do I gain performance using...
8 Jun 2018 by Mada Naga Sankar
I have created a webapi with jwt authentication. I am able to get response without authorization, when i have added authorize attribute to controller, its giving me unauthorized which is correct. But when i sent authorization header its giving CORS error and request not working. Is there any...
6 Mar 2017 by Cathy Wun
This is the first part of building an Earnings Tracker using Angular 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.
25 Mar 2020 by Quí Nguyễn NT
This is a demonstration of a basic example of single page Angular application and micro-service architecture on Azure.
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();...
1 Jun 2017 by Richard Deeming
UploadValuesAsync[^] does not wait for the request to complete. It starts a background operation to make the request, and returns immediately. When the request is complete, the UploadValuesCompleted[^] event will be raised. Your method is most likely exiting before the request has been...
5 Nov 2020 by Virendra S from Bangalore, Karnataka
i am getting the CORS issue while accessing the deployed ASP.Net Web API 2 while running the angular app locallly. the same API is working with postman. Error: Access to XMLHttpRequest at...
5 Nov 2020 by Richard Deeming
Either you haven't deployed the CORS-enabled version to the server, or the API you've updated isn't the API you're calling. Use your browser's developer tools to inspect the network request, and look at the response headers to check the...
9 Jul 2018 by Rohit Singh
Hello, I'm creating a webApi Project for simple get request. I'm using MySql as database. Everything was working fine until I'm using it on my Local IIS Server but when I deployed my project on production server it shows below error Server Error in '/SAMPLEAPI' Application Parser Error...
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...
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 Thomas Daniels
Both ways will work. A HttpClient can be reused.I recommend using a single HttpClient instance. With having a single instance, you can benefit from the DefaultRequestHeaders property[^] and BaseAddress property[^]. Even more importantly, just using a single HttpClient instance will improve...
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...
2 Feb 2020 by Member 11183217
hi, I have tried the swagger ui versioning by using the .net core 3.1 with API 2.0. i have completed this scenario up to controller level. but i dont know how to do this versioning for controller Action...anyone can you please help me on this i have struggled past 3 days on this. help me...
2 Feb 2020 by RickZeeland
Maybe you can try NSwag, see: https://elanderson.net/2019/10/swagger-openapi-with-nswag-and-asp-net-core-3/[^] https://www.slant.co/topics/1397/viewpoints/20/~best-web-frameworks-to-create-a-web-rest-api~nswag[^]
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...
21 Mar 2019 by Richard Deeming
You're returning an array containing the value of every column from every row, flattened out into a single list. You need to return an array of objects instead: while (reader.Read()) { columnNames.Add(new { rownum = (Int64)reader["rownum"], code = (Int32)reader["code"], ...
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...
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...
8 Sep 2019 by pkfox
What does the debugger tell you ? No one will trawl through all that code for you - make more of an effort to pinpoint the problem
9 Sep 2019 by pkfox
Step through your code in the debugger and look at the values as you go - you say the data is identical but it it obviously isn't
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); ...
8 Feb 2020 by Aram Tchekrekjian
How to create and deploy your first ASP.NET Core Web API on IIS
2 Jul 2019 by Mustafa Kok
Developing a very simple Web API architecture using ASP.NET Web API2 whose operations can be extended by just adding new operation types
11 Jul 2017 by Ansel Castro
Develop SOLID back-ends exposed through a REST API with ODATA support and DTO mapping using Enterlib.NET.
2 Jul 2018 by Ramnivas Kuma sharma
I am sending Employee Data in Web APi-2 Action Method and after that calling repository to insert/update/delete. Every time using Httppost Verb and getting data in action method after that repository calling my store procedure and insertion/inundation/deletion is working proper. So without using...
2 Jul 2018 by Krunal Rohit
Both PUT and POST can be used for creating. In more general, PUT is to create a resource whereas POST is to update a resource. Your answer is here[^]. KR
3 Jan 2018 by VasanthPorcheziyan
Hi, I am trying to display stored stream in mongodb GridFS as image in angularjs using webapi c#. I am using mongodb 2.4.4 in my project. MongoDB Package : [^] What I have tried: I saved the stream from angular to mongodb using the below code. using (var stream = await...
9 Dec 2019 by Member 10033441
Hi All, I am trying to download file but there is no content present after download.Please assist me to resolve it.Below is my code. WebApi Code ------------- [Authorize] [HttpPost] [Route("downloadStaticDocument")] public HttpResponseMessage...
25 Jun 2018 by Member 11906002
I am using below code in web api .net core to get the request body content and it is working fine for JSON input ie., Content type - "application/json" [HttpPost] public void Post([FromBody] dynamic messages) {} But when I pass xml in request body ie., Content Type - "application/xml",...
30 Oct 2020 by Virendra S from Bangalore, Karnataka
Controller: public class testADOController : ApiController { [HttpGet] public testOrg GetOrgTreeStr(int emp_no) { return testadoBL.GetTestOrg(emp_no); } } WEbAPiCOnfig.cs file data: ...
30 Oct 2020 by Richard Deeming
In your route, the parameter is called id. In your method, the parameter is called emp_no. Either change your method parameter name: public testOrg GetOrgTreeStr(int id) or pass the value in the querystring: ...
5 Nov 2020 by Virendra S from Bangalore, Karnataka
I am trying to fetch a image from MS SQL DB. GetEmpImg() is getting called by in other class, i want return the bytes data. but return code is not reachable my code snippet: public static byte[] GetEmpImg(int emp_no) { ...
5 Nov 2020 by OriginalGriff
You can't return byte data there: it doesn't exist, because you haven't read it. You only read any data when there is at least one row available - and there should be only one row, so the while loop is redundant, just use an if instead - and...
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...
28 Apr 2019 by Member 12919448
Hi, I used kendo.dynamic.linq.DataSourceResult to implement filtering in server side. [AcceptVerbs("GET","POST")] public DataSourceResult Filter(Models.DataSourceRequest request) { if (request != null) { request.Filter.Field =...
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'...
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 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...
2 Feb 2017 by sonymon mishra
It will create different token for each user session. This is like a one-time user token.What you can do is:1. Call "http://address/Token" along with username=xxxx&password=xxxx&grant_type=password as request as body.2. Store the received token locally(in session variable if using server...
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...
25 Aug 2021 by Richard Deeming
Quote: [ResponseType(typeof(Products))] public IQueryable GetProducts() The ResponseType value doesn't match the type you are returning. But since you're returning a concrete type, rather than an IHttpActionResult, that attribute is...
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":...
17 Aug 2021 by Richard Deeming
Quote: string[] str = response.RequestMessage.RequestUri.LocalPath.Split('/'); // str contains: { ..., "PDF_Report.aspx" } ... str[str.Length - 1] = str[str.Length - 1].Replace(".aspx", ".pdf"); // str contains: { ..., "PDF_Report.pdf" } var...
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...
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.
27 May 2018 by Member 12118045
I had a requirement to use Ad authentication for web api I had implimented using "WindowsAzureActiveDirectoryBearerAuthenticationOptions" but i am getting below error at ValidateToken while I am hitting with the client IDX10500: Signature validation failed. Unable to resolve...
5 Dec 2017 by Vincent Maverick Durano
This article demonstrates how to build an ASP.NET Core application using Entity Framework Core Code-First development with Web API and MVC.
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...
20 Dec 2018 by vaibhav1800
Hi, Lets say I have implemented Token based Authentication and what I do is that I store the token in LocalStorage of WebBrowser. Everything is fine but I have not taken care of the hack. I mean Since the token is in the browser storage for lets say 1 min but hackers can still hack it in 1...
20 Dec 2018 by Nathan Minier
This depends a bit on the level of control that you have over what is in the javascript included on your page. If all you are ever going to have is your own JS and you don't use any third-party frameworks or libraries, then the local store is fine. If you think you might ever use an external...
10 Oct 2017 by Member 11767325
make sure that Microsoft.Owin assembly in publish folder
8 Apr 2020 by Member 11183217
I want to get all the messages from Telegram channel and display them in an ASP.NET webpage (c#,mvc)... What I have tried: i have tried all the ways and i didn't get the reference as well can you please some one give me the reference it will...
4 Jan 2017 by Nick Van Tassell
I have the following code: $.ajax({ type: 'GET', url: 'http://localhost:51914/PlayerPortal/User/Test', }).done(function (data) { self.user(data.userName); // Cache the access token in session storage. ...
4 Jan 2017 by Nick Van Tassell
It IS due to CORS: Origin is defined by 1) host, 2) port, and 3) protocolI guess I'll make it all in one app, like I've seen everywhere else.
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 => ...
7 Jan 2020 by MadMyche
Have you looked into there GIT repository and read this issue? Disabling swagger ui · Issue #301 · domaindrivendev/Swashbuckle · GitHub[^]
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 ...
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 :...
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);
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...
16 Feb 2017 by SteveHolle
You could try using a BackgroundWorker thread to execute the long running process and use ReportProgress to send progress back to your main thread. The Background thread will send a callback when it's completed. Your main thread would then be primarily responsible for running "fancy loading...
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...
12 Sep 2018 by Member 11993385
How can I return an entity with it's related entities in a Web API method, and call it from a MVC application. I have a Web API in which I am returning a Person entity, I am also returning all the policies linked to the Person entity. So a Person can have one or many Policies. So far I am...
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 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...
22 Oct 2021 by OriginalGriff
Quote: No error is coming in all above code. First i have created an updated stored procedure to update the record and then implemeted the put method in web api controller and then consumed it in the mvc controller but whenever i try to update...
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...
11 Jan 2018 by Member 13605985
i want to upload image to server using web api in mvc dot net. i am new at learning of Web Api and i want to upload image to server using web api. please guide me how i can do this. What I have tried: string img = username + "_" + labTestId + fb; ...
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[^]
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...