All Questions
Tagged with .net-4.5 asp.net-web-api
106
questions
54
votes
3
answers
59k
views
Using a proxy with .NET 4.5 HttpClient
I'm troubleshooting a bug with a service I call through .NET's HttpClient, trying to route the request through a local proxy (Fiddler), but my proxy settings seem to not be taking effect.
Here's how ...
42
votes
4
answers
90k
views
System.Web.Http is missing after a .NET 4.5 upgrade
I've just upgraded my solution to .NETE 4.5 using Target Framework Migrator, and then the package manager console command:
Update-Package -Reinstall -IgnoreDependencies
In one of my projects I am ...
31
votes
2
answers
53k
views
DelegatingHandler for response in WebApi
I am currently using several delegation handlers (classes derived from DelegatingHandler) to work on the request before it is sent, for things like validating a signature etc. This is all very nice, ...
26
votes
5
answers
85k
views
Json does not exist in the namespace System
In this tutorial: http://www.asp.net/web-api/videos/getting-started/custom-validation Jon uses
dynamic error = new JsonObject();
with
using System.Json;
I guess it's the JsonObject here: http://...
24
votes
2
answers
7k
views
HttpContext.Current.Items after an Async operation
Consider the following ASP.NET Web API Delegating Handler:
public class MyHandler : DelegatingHandler
{
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage ...
18
votes
2
answers
36k
views
How to setup Request.Header in FakeHttpContext for Unit Testing
I have a FakeHttpContext I have been trying to modify to include some headers for testing purposes
public static HttpContext FakeHttpContext()
{
var httpRequest = new HttpRequest("", "http://...
13
votes
3
answers
21k
views
Passing JSON Array from Javascript to Web API Controller method
I was not able to get the JSON array parameters in web api controller method (SaveDetails).
Here are my code.
JavaScript Code:
$.ajax(
{
url : "api/Test/SaveDetails",
type : "...
12
votes
4
answers
28k
views
How do I remove headers from my Web API response? [duplicate]
New Web API 2.0 project so we have full control over the entire request / response pipeline.
How do we remove the "X-" headers from a response sent by ASP.NET Web API response? Specifically, at the ...
11
votes
2
answers
15k
views
POST a string to Web API controller in ASP.NET 4.5 and VS 2012 RC
I am new to WebAPI and trying to learn it. I have an WebAPI controller to which I am trying to POST a string using WebClient from my Unit Test.
I am posting a string to my WebAPI using following code ...
11
votes
2
answers
2k
views
Forcing ASP.NET WebAPI client to send a client certificate even when no CA match
I have a specific application that requires the use of client certificates for mutual authentication of HTTPS requests. The server has a flexible certificate validation policy that allows it to ...
9
votes
4
answers
11k
views
.net 4.5 ASP.Net web API JSONP support
Does anyone know if returning JSONP is supported out of the box in .net 4.5 ASP.NET WEB API?
I've found plenty of "roll your own" for earlier versions of MVC or .net but there doesn't seem to be ...
8
votes
3
answers
6k
views
Using ModelState to return errors from WebAPI 2
I am trying to use ModelState object to send Errors to the Client; I am using asp.net Web API for the Service.
On the Web Service side, I am doing this.
public HttpResponseMessage VerifyData(...
8
votes
2
answers
13k
views
Correct usage of await async in webapi
I have a WebApi that for each incoming request, calls 2 separate webservices, performs some post processing and returns the results.
The first webservice call is cached locally for 1 hour, and the ...
7
votes
1
answer
24k
views
The maximum size of object that can be passed as Parameter to POST method
I have a web API controller with a POST method as follows.
public class MyController : ApiController
{
// POST: api/Scoring
public HttpResponseMessage Post([FromBody]MyClass request)
{
...
7
votes
1
answer
15k
views
Thread.CurrentPrincipal is authenticated but ClaimsPrincipal.Current is not
I'm using Claims based Authorization in my WebApi project and have a method where I check if the current Identity is authenticated. When I use ClaimsPrincipal.Current the current Identity is not ...
6
votes
2
answers
14k
views
Method not found: 'System.Net.Http.Headers.MediaTypeHeaderValue System.Net.Http.Formatting.JsonMediaTypeFormatter.get_DefaultMediaType()'
I have a method named GetJSONResponse(...) and here's an extract:
var response = new HttpResponseMessage(httpResponseCode)
{
Content = objectToSerialize != null ?
...
6
votes
1
answer
341
views
Why await both the asynchronous request and the reading of its contents?
Why is it necessary in .NET Web API to have a a method that reads the content of an HTTP response asynchronously, given that there is already a method to make the request asynchronously? Said another ...
6
votes
1
answer
12k
views
App_Global.asax.compiled and App_Global.asax.dll missing? WebApi .NET 4.5 project
During our adventures of building a 'simple' API using WebAPI we've had our fair share of issues as any project does, however I am unable to find any such resource that can explain the following ...
6
votes
1
answer
4k
views
Invoking a web service - asmx - through a Microsoft Web API end point?
I am using Microsoft ASP.NET Web API 2 and one of my end points has to internally invoke a legacy asmx web service.
Is this the correct way?
...................................................
...
5
votes
1
answer
3k
views
Generate Swashbuckle API documentation based on roles / api_key
I’m using Swashbuckle (5.3.2) and it generates a nice API documentation.
To clarify my problem, I set up a small example project with no real meaning.
The API can only be used with a valid API key.
...
4
votes
4
answers
5k
views
Is it possible to use ASP.NET application caching in web API?
For example, in a ASP.NET page you would do something like
Cache.Add({...}) and access it via Cache["key"]. In this context, Cache is the System.Web.Caching.Cache object.
Is there anyway to do this ...
4
votes
1
answer
2k
views
Web API and .NET 4.5: Claims and rights
Is there a best practice for using claims for right-management?
I am using the new .net 4.5 and the new claim classes.
Currently I do something like that:
new ClaimsIdentity(new List<Claim>
...
3
votes
3
answers
8k
views
The parameterized query expects the parameter p1 which was not supplied
I have a stored proc as below:
CREATE PROCEDURE [dbo].[MyProc]
@p1 as int,
@p2 as smalldatetime,
@p3 as int,
@p4 as varchar(255),
@p5 as int = null,
@p6 as numeric(18,2) = 0,
...
3
votes
2
answers
4k
views
How to async stream a file from database to webclient without buffering
I'm trying to async stream a file from sql server out to a web client using .net 4.5 and web api.
I'm using SqlDataReader.GetStream() to get a stream from the db. However, I'm not sure how to wire in ...
3
votes
1
answer
3k
views
How to cancel an async WebApi action after timeout?
Using ASP.Net WebAPI, I have a controller with an asynchronous action similar to the following:
[HttpPost]
public async Task<string> DoSomething(string foo)
{
var result = await ...
3
votes
1
answer
2k
views
Is it wrong to use routes versus query string parameters? [closed]
I have a Web API controller with two actions. One action returns a list of all entities from the database. The second action takes a query string parameter and filters the entities.
The search action ...
3
votes
1
answer
3k
views
Web API OData Controller and Authorization Attribute
I am trying to use an MVC style authorization filter as an attribute on the Get() action method of an OData Web API controller, but the authorization filter is ignored. Can authorize attributes be ...
3
votes
3
answers
572
views
Saving settings/variables/permissions in memory instead of looking them up on each API call?
I have an API set up that allows placing orders, looking up product info, reporting, etc. Each API key has specific permissions on which controllers/methods they can or can't access, as well as fields ...
3
votes
3
answers
6k
views
Web API Sync Calls Best Practice
Probably this question has already been made, but I never found a definitive answer. Let's say that I have a Web API 2.0 Application hosted on IIS. I think I understand that best practice (to prevent ...
3
votes
1
answer
3k
views
ASP.NET Web API on .net 4.0
I have ASP.NET web api project created on .NET v 4.5
I later i was decided to change framework to 4.0
After changing i got an error. VS can not regognize types and namespaces althougt all required ...
3
votes
3
answers
16k
views
How do I get the current cookie / session ID from a HttpResponseMessage?
I try to use the new .net 4.5 HttpClient from System.net.http.
I set-up my client like this
CookieContainer cookieJar = new CookieContainer();
HttpClientHandler handler = new ...
3
votes
1
answer
811
views
Forward Server-Sent-Events from another service to the caller - C# ASP.NET WebApi
I have a web app made with ASP.NET (constrained to .NET 4.5) using the WebApi which has a controller class.
In this controller, I had to make two new endpoints who have to call another service which ...
3
votes
2
answers
551
views
How should I implement Nlog logger to reduce copy/paste tedium?
I'm working on a .NET solution that will include MVC and Web API controllers. After admitting I deserved better than a roll-your-own logging solution and could benefit from some of the features in a ...
3
votes
1
answer
154
views
Same Entity for Web Api and WCF
I have entities that uses for WCF service at the moment.
Sample like
[DataContract]
public class Student
{
[DataMember]
public long Id { get; set; }
[DataMember]
...
3
votes
1
answer
1k
views
How to send an HTTP request and don't process the response
As a service, my server sometimes needs to notify clients their resource is ready for use.
For that to happen, they give me a URL as a callback and when the resource is ready I send an HTTP request to ...
3
votes
1
answer
4k
views
Generate and stream Zip archive without storing it in the filesystem or reading into memory first
How can I asynchronously take multiple existing streams (from the db), add them to a zip archive stream and return it in asp.net web api 2?
The key difference with the other "duplicate" question is ...
3
votes
1
answer
243
views
WEB API call stops working after introducing the "await" keyword
I have a simple web api method which retrieves a list of items from a database. When the method looks like this it works and the items are displayed in the UI:
[ActionName("GetServices")]
public ...
2
votes
1
answer
2k
views
ASP.NET Web API Controller Best Practice - Action Definitions
I'm running into a situation where my HttpGet action in my Web API controller has multiple ways to be called based on parameters specified in the query string.
I need to be able to handle the ...
2
votes
2
answers
895
views
How do I handle multiple parameters as an OR in a Web API querystring?
Suppose I have this URL:
api.XXX.com/cities?risk=a,b&rating=x,y
What I want is a list of cities with a Risk category of A or B AND a Rating of X or Y. How should I implement this?
I understand ...
2
votes
1
answer
1k
views
No events from custom .Net 4.5 EventSource ETW provider in PerfView
I created an EventSource (WebApiEventSource) in my ASP.NET WebApi application (to is as ITraceWriter-implementation):
[EventSource(Name = "WebApi")]
public class WebApiEventSource : EventSource
{
...
2
votes
1
answer
706
views
Invoking a web service in a Web API Project...in which layer to invoke? [closed]
I am using Microsoft ASP.NET Web API 2 and one of my end points has to internally invoke a legacy non-Microsoft web service (not asmx or svc) .
Which layer should I invoke this in?
I currently have :...
2
votes
1
answer
1k
views
Why is the response content in this streaming service example empty?
I could really use some help understanding why this unit test is failing. I suspect it's due to the way I'm handling the streams. I have a number of other tests that successfully use this self-hosting ...
2
votes
1
answer
612
views
Why does this code fail when executed via TPL/Tasks?
I am using System.Net.Http to use network resources. When running on a single thread it works perfectly. When I run the code via TPL, it hangs and never completes until the timeout is hit.
What ...
2
votes
1
answer
1k
views
Castle.ActiveRecord.dll not compatible with ASP.NET MVC 4 Web API
MSFT claims that .NET 4.5 is backwards compatible with .NET 4. I went ahead and installed .NET 4.5 and VS 11, then created a new ASP.NET MVC 4 Web API project. When I reference the Castle.ActiveRecord....
2
votes
1
answer
3k
views
Using multiple delegating handlers in a web API call
I have a web API call that needs to make use of 2 delegating handlers, but I never seem to get in to the second handler. The route is registered with the handlers. I am not allowed to set the handlers ...
2
votes
1
answer
849
views
Create Delegate throws a binding error due to signature or security transparency
I am using C#4.0 and .NET 4.5.
I have this class which is the point of entry in the current context:
public static class HttpConfigurationImporter
{
public static readonly ...
2
votes
0
answers
2k
views
Web API, model binding, [FromUri], and WebApiExplorer not playing well together
I have a fairly simple web api project and have the following method in a CustomerController:
public class CustomerController : ApiController
{
[HttpGet]
public UpdatePasswordResult ...
1
vote
1
answer
3k
views
WebApi 2 Authentication and ASP.NET MVC 5 Applications
I'm new to the ASP.NET MVC 5 and WebAPI 2 technology.
I am currently developing a project for my school.
This project will be used on computers or mobile.
I have a Visual Studio solution like this:
...
1
vote
3
answers
2k
views
Elmah in Web API 2 without MVC .Net 4.5.1
I am trying to implement Elmah error logging in an ASP.NET WEB API 2 project that doesnt use MVC.
I tried both Elmah and Elmah.mvc nuget packages and i am not even able to browse to the emlah page ...
1
vote
2
answers
2k
views
Principal with new ASP.NET Web API
Some time ago I built API using asp.net Web-api beta. I read somewhere that when hosted in IIS, the web-api inherits the Identity from web application in which its running. My api is also running ...