Questions tagged [asp.net-web-api]

ASP.NET Web API is a framework for building HTTP services for clients like browsers and mobile devices. It is based on the Microsoft .NET Framework and an ideal choice for building RESTful services.

ASP.NET Web API is a framework that makes it easy to build that reach a broad range of clients. These Web-APIs can be consumed by any clients capable of communicating via HTTP (including browsers, mobile clients, desktop applications, and other web applications). It is useful for building ful applications on the Framework.

Web API was created by Microsoft and released on 15th August 2012.

Web API can be hosted:

  • within
  • outside of ASP.NET and IIS - also known as "self-hosted" (i.e. directly inside a Windows service, WPF application or console application)
  • in memory (not accessible via HTTP from outside of the process, but useful for end-to-end testing scenarios or mocking).

As Microsoft had multiple approaches within its technology stack for creating REST services; WCF Web API, ASP.NET MVC controllers returning JsonValue results; this represents a rationalisation and merging of these efforts. The ASP.NET Web API stands separately from WCF and does not deprecate (at this point) the WCF Web HTTP programming model.

Related tags

37671 questions
12
votes
5 answers

WEB API - Authorize at controller or action level (no authentication)

I have an existing API that has No Authentication. It`s a public Web API which several clients use by making simple requests. Now, there is the need to authorize access to a certain method. Is there any way to do this, keeping the rest of the…
JCruz
  • 346
  • 1
  • 3
  • 9
12
votes
4 answers

CORS not working with route

I have an issue with an endpoint on my web api. I have a POST method that is not working due to: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.…
NicoRiff
  • 4,803
  • 3
  • 25
  • 54
12
votes
5 answers

Use MemoryStream and ZipArchive to return zip file to client in asp.net web api

I am trying to return zip file from asp.net web api to client using The following Code: private byte[] CreateZip(string data) { using (var ms = new MemoryStream()) { using (var ar = new ZipArchive(ms, ZipArchiveMode.Create, true)) …
Kob_24
  • 592
  • 1
  • 10
  • 26
12
votes
1 answer

Difference between wcf restful services and WEB API

I am query for a long time now.Where exactly we need to use WEB API and where should we use WCF restful services. What ever we want to achieve in WEB API we are able to achieve in WCF Rest. I tried to dig into answers but i got we need to do extra…
abhijit
  • 187
  • 1
  • 1
  • 12
12
votes
4 answers

Running Selenium on Azure Web App

I have an Azure Web App that I want to use to screen scrape a website when I call an Action on a controller, like so. var driver = new PhantomJSDriver(); driver.Url = "http://url.com"; driver.Navigate(); var source = driver.PageSource; var…
12
votes
5 answers

Web API and HTTP Module

We have an HTTP Module that decodes all encoded requests. It works great with all WCF requests, but NOT in Web Api requests- in Web Api the request (both POST and GET) gets to the service still encoded I see that it Hits the HTTP Module…
DasDas
  • 571
  • 3
  • 9
  • 32
12
votes
2 answers

Benchmarking ASP.NET concurrent requests poor results

I have the following code that I benchmark with jMeter and get about 3000 request per second on my localhost machine(the await is missing intentionally to run synchronously): public async Task Get() { var resp = new…
realPro
  • 1,713
  • 3
  • 22
  • 34
12
votes
1 answer

Retrieving and persisting state across requests

I am writing my first ASP.NET Web API application. I am familiar with other web application frameworks (mostly Symfony, but also Django, and to a lesser extent RoR). I am struggling a bit, to understand the sequence of events that occur after a…
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
12
votes
1 answer

set web api route handler when using route attributes

I have a custom route handler witch i would like to use on different controllers. Right now the only way i get my controllers to use this route handler is to set it like this RouteTable.Routes.MapHttpRoute( name: "CustomRouteHandler", …
MacGyver
  • 6,579
  • 1
  • 18
  • 11
12
votes
3 answers

ASP .NET WebAPI Route Data Schema

Currently, we are using a route like this: [HttpPost] [Route("upload")] public async Task Upload(dynamic uploadedData) { JArray files = uploadedData.pdfs; // ... } Rather than using dynamic, I'd like to have a schematic…
Scotty H
  • 6,432
  • 6
  • 41
  • 94
12
votes
2 answers

HttpClient in using statement causes Task cancelled

I created a FileResult : IHttpActionResult webapi return type for my api calls. The FileResult downloads a file from another url and then returns the stream to the client. Initially my code had a using statement like below: public async…
Rafi
  • 2,433
  • 1
  • 25
  • 33
12
votes
2 answers

How does UseWindowsAzureActiveDirectoryBearerAuthentication work in validating the token?

I am following the below GitHub sample for implementing Authentication mechanism across WebApp and WebApi. https://github.com/AzureADSamples/WebApp-WebAPI-OpenIDConnect-DotNet I am using a single App registration for both WebApp and WebApi, get a…
SteelBird82
  • 759
  • 3
  • 10
  • 23
12
votes
4 answers

Publish WebApi to Subfolder

I have an out-of-the-box Visual Studio 2013 SPA using WebApi. I added Twitter authentication to Startup.Auth.cs and all of it works just fine when I publish to the root of an IIS web site or when I debug in VS with localhost. What I can't figure…
smoore4
  • 4,520
  • 3
  • 36
  • 55
12
votes
3 answers

WebApi attribute routing - Bind route parameter to an object for GETs

Currently for every GET I have to manually create a query object from the route parameters. Is it possible to bind directly to a query object instead? So, instead of : [Route("{id:int}")] public Book Get(int id) { var query = new…
kimsagro
  • 15,513
  • 17
  • 54
  • 69
12
votes
1 answer

Remove JSON.net Serialization Exceptions from the ModelState

Problem Background To save myself from duplicating validation logic I am following a pattern of pushing Server side ModelState errors to my View Model (MVVM KnockoutJS). So by convention my Property Names on my KO ViewModel Match the Properties my…
SimonGates
  • 5,961
  • 4
  • 40
  • 52
1 2 3
99
100