Click here to Skip to main content
15,886,788 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 Score

WebAPI2 

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.
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.
11 Jun 2017 by Livio Francescucci
Use a JWTToken to access a .NET Core Web API leveraging IdentityServer4 / OAuth2.
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.
8 Feb 2020 by Aram Tchekrekjian
How to create and deploy your first ASP.NET Core Web API on IIS
31 Jan 2017 by Cathy Wun
This is the first part of Building an Employee Tracker using AngularJS and ASP.NET Web API Series.
12 Feb 2017 by levelnis
A quick example to show how to check for a duplicate username
18 Apr 2018 by WAMCE
I am working on one MVC application, where there is separate WEB API project also. Now I want to implement update email functionality based on OTP verification from mobile via WEB API. Web API is stateless but still, I want to implement SESSION in my code so that I can access OTP value in...
27 Dec 2018 by tranthanhtu.vn
[TinyERP: SPA for Enterprise Application]Manage Staffs - Part 2
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...
31 Aug 2019 by Thomas Daniels
I can't see the code you use to render the image, but I'm guessing that you create an img tag with as src the API response. D:\Images1\1.jpg is not a file path that will be recognized by your browser. You'll have to use this: file:///D:/Images1/1.jpg But note that if anyone accesses your MVC...
8 Dec 2019 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).
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...
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...
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...
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.
23 Jul 2017 by Harmen Stoopendaal
See for solution this repo: GitHub - Harmen1969/SignalR-Postgresql-: Real time push notification using SignalR and PostgreSQL[^]
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 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
8 Oct 2018 by Member 10089399
[HttpGet] [ProducesResponseType(typeof(Employee), 200)] [Route("api/GetEmployees")] public IActionResult GetEmployees() { try { var data = db.Employees.ToList(); if (data == null) ...
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...
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...
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...
30 May 2019 by MadMyche
The best way to do this would be to not build your own JSON from scratch; and to use JavaScripts FormData object to assemble the information and submit it. Thoughbot | Ridiculously simple Ajax uploads with FormData[^] SitePoint | Easier Ajax With the HTML5 FormData Interface — SitePoint[^]...
11 Dec 2019 by MadMyche
Well... the problem is quite evident; many of these are various control or otherwise special characters. The %, &, #, and / should be visible to anyone who has looked at a URL as separators, fragment identifiers, routing, and escape characters. I personally would not use GET with a password, as...
28 Jan 2020 by MadMyche
Your assigned project at the business level is not always going to be the same as your programming project. The backend requirement of your assignment is to use SOA (Service Orientated Architecture). This should be a standalone project and if it were mine I would use WebAPI for this. Your...
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[^]
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...
22 Apr 2020 by Richard Deeming
There is no native support for multiple result sets in Entity Framework. If you're using EF6, you can get the ObjectContext and manually translate the results, as described in this SO answer[^]: using (TableDBContext context = new...
26 Apr 2020 by MadMyche
You don't. Those are necessary portions of the URL to tell the browser what protocol to use (HTTPs, FTP, Gopher), the domain go to (localhost), as well as what port number (00000) to use Once it gets to localhost:0000, then it is your web...
21 May 2020 by MadMyche
I would probably start a new project, getting all of the authentication in and then migrate the code from your current application. I would recommend reading through the following links to MS Docs, and then go step by step once you understand...
8 Jun 2020 by Richard Deeming
It looks like you're using the Strathweb.CacheOutput library. Looking at the documentation, the value passed to InvalidateCacheOutput needs to be the method name whose cache you want to invalidate. You don't have a method called y on the...
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...
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.
24 Nov 2016 by levelnis
How to use DataTables with Web API Part 2: Making a POST request
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...
7 Dec 2016 by RebelStar
I have 2 web servers.I published my WebAPI on both servers.The published application on WebServer-1 runs properly but on WebServer-2 it gives me 400 error.What I have tried:I republished my WebAPI and CrossChecked path of root folder.
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...
19 Dec 2016 by Member 12376348
Hi Every oneI am developing the web api project in that i implemented the OAuth Security but now the client want saml with oauth so i don't have an idea how to implement saml i searched lot of sites but i did not get the idea of code. and also how to configure IDP and SP with our app please...
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...
20 Dec 2016 by pjaar89
Hello,Can you try Clients.Caller.NotificationToClient(NotificationResult);Also if you want to map users and connections you should read Mapping SignalR Users to Connections | The ASP.NET Site[^]
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...
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...
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. ...
6 Feb 2017 by Mike Hankey
I'm trying to do an ajax POST in an mvc 5.0 WebApi web application. Can do a GET just fine but when I try to update a field using GET that has a large amount of data I get the 405 error.Am I on the right track or am I looking in the wrong direction?Also is there any good/simple...
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...
5 Feb 2017 by Sachin Kakade
Please check below code api example for 405 example hope its help you.troubleshooting-http-405-errors-after-publishing-web-api-applications.
6 Feb 2017 by Mike Hankey
Update just an FYI for those in a like position, found a solution after much gnashing of teeth;Add to web.config;
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...
26 Feb 2017 by Sameera Liyanage
From last two days i am triing to connect postgress database from web api. but i couldn't do that. please help me to solve this. Below is my connection string.
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...
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...
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.
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,...
28 Mar 2017 by Richard Deeming
What you've described is an Insecure Direct Object Reference:Top 10 2013-A4-Insecure Direct Object References - OWASP[^]Using a sequential number to access data for different records makes it trivial for an attacker to guess the URL for other users' data.You can make their life harder...
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); ...
1 May 2017 by User 4180254
Check if below hepls you with your question. Troubleshooting HTTP 405 Errors after Publishing Web API 2 Applications | Microsoft Docs[^]
22 May 2017 by saumil jariwala
//I have used following method //This is my api which i have put in Sendgrid > Mail Settings > Event Notification > //http://username:pwd@beta.comivo.com/api/sendGrid/Webhook [Route("Webhook")] [HttpPost] public void SendGrid([FromBody]SendGridSentEvent[] eventList) ...
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 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...
15 Jun 2017 by Member 10371658
i am working on MVC and Web Api project and i have added the Elmah nuget package in the both application, and it's working fine, exception log is writing into database, but when i deploy the application on IIS server. it's showing the duplicate name="Elmah" and other elmah related tag into the...
26 Jun 2017 by Richard Deeming
Simple: You don't. Those headers are part of the HTTP grammar. If you removed them, your response would no longer be valid. Hypertext Transfer Protocol - Wikipedia[^] List of HTTP header fields - Wikipedia[^] You can change the Cache-Control, Expires and Pragma headers by setting the...
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...
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...
12 Jul 2017 by Saranya Mahesh
I have a base web API project which does the main operations and I have custom/bespoke web API project. The custom project does extra functions(bespoke) additional to the existing functions done by the base API. How do I basically convert an API project to a plugin and access it from base API...
16 Jul 2017 by Nawab Ahmad
Hi All, I am working on new project where i have to use Angularjs and webapi. My question is shall i create different different project for both angularjs and webapi or i can create a single project including MVC wepi and Angularjs 2. Please suggest me which way i have to create. What I have...
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 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)
29 Jul 2017 by Member 10371658
i have tried to get the data from database, i have product controller and two entity are related(Category and supplier) to the product entity. error occurred: url: http://localhost:43938/api/products Error: {"Message":"An error has occurred.","ExceptionMessage":"The...
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...
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...
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;...
7 Aug 2017 by Member 13350786
Did you resolve your issue? Can you please post your complete code(capture sendgrid event notification in C#) here, I need to implement is asap.
15 Aug 2017 by manish.communityhub
I want export to excel in angular and web api using npm filesaver In Console I am getting the error message : The request body isn't either a blob or an array buffer Here is my code Web Api : public HttpResponseMessage GetExcelData() { try ...
15 Aug 2017 by manish.communityhub
Ok I got the solution, very simply we can do it. Web Api public void GetExcelData() { string sFileName = System.IO.Path.GetRandomFileName(); string sGenName = "Friendly.xls"; System.IO.FileStream fs = null; fs =...
21 Aug 2017 by NaVeN Kumar
Hi, I would like to filter the records based on child table data using odata query. Example I have tables like below. Employee contains empId and Name, EmployeeText is having empId, languageid and Text Employees EmpId Name 1 Test 2 Test2 EmployeeText empId LanguageId Text 1 ...
10 Oct 2017 by Member 11767325
make sure that Microsoft.Owin assembly in publish folder
3 Nov 2017 by manish.communityhub
here is my code $('#btnLogin').click(function () { var body = {'grant_type': 'password','Email':$('#Email').val(),'password': $('#Password').val()}; alert(JSON.stringify(body)); $.ajax({ url: 'http://localhost:46382/Token', ...
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...
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...
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...
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...
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...
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 ?? ...
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...
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...
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[^]
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...
1 Jul 2022 by Member 10738936
This issue comes on live server. In local IIS its working. for deserialize i am uing var data = JsonConvert.DeserializeObject(response.Content); this is my json: {"Table":[{"OrganisationID":1001,"NAME":"LORD MEHER INTER...
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...
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...