Questions tagged [webapi2]
127 questions
7
votes
2 answers
How do you specify the location when using handleexeption annotation for a 302 status code
Using c# Web Api 2, I have code that throws an InvalidOperationException. When returning a status code of 302, how do provide a location for the redirect using the HandleException annotation?
[HandleException(typeof(InvalidOperationException),…

TheEmirOfGroofunkistan
- 5,476
- 8
- 37
- 53
5
votes
0 answers
Using [FromBody] in GET Method of WebApi Controller
So I know how to use [FromUri] and [FromBody] on a "Post" method of my WebApi Controller. Needless to say [FromUri] on a "Get" method is unnecessary but explicit, and works well. My problem is I want to WebApi to parse my HttpBody on a "Get" method…

griftopia
- 135
- 1
- 3
- 10
4
votes
1 answer
ASP.NET Web API 2 primitive type from body (boolean) error
I have an action
[HttpPatch]
public IHttpActionResult foo(int id, [FromBody]bool boolVariable)
{
return Ok();
}
I am still debugging and when I try to send some data with Postman I get a strange error
"Message": "The request is invalid.",
…

john
- 41
- 1
- 3
4
votes
1 answer
ASP.NET Web API 2 on Visual Studio for Mac 2017 RC
I am new to Mac and was trying to build a Web API2 with Visual Studio 2017 for Mac. I am not able to see Web API 2 packages (Controller option is missing, I am able to create a MVC project but even when I select Empty Web Application -> Web API…

DeiJ Wrapp
- 116
- 1
- 11
4
votes
3 answers
TotalCount for paging with dapper
I'm using dapper to get result set from stored procedure into object list and return it to the client as json:
public IHttpActionResult Test()
{
List gridLines;
var cs =…

Simon
- 1,955
- 5
- 35
- 49
3
votes
1 answer
Is it possible to pass more than one complex type parameter separately in the web API 2 Controller post method?
I know [FromBody] allows only one complex type as a parameter. I just wanted to know, is there any other way to do so? Any help or knowledge would be greatly appreciated! Thanks! :)
This is my controller
public HttpResponseMessage Post([FromBody]…

Ravikant Gupta
- 205
- 2
- 11
3
votes
0 answers
How to make an API throw 406 or 415 codes during content negotiation
When building a RESTful API, it is desirable to issue return codes of 406 (not acceptable) and 415 (Unsupported media type) when doing content negotiation.
What is not clear to me is exactly how to return these codes in a WebAPI2 app that is using…

mcwrath
- 45
- 4
2
votes
0 answers
Decoding access_token in Hangfire's IDashboardAuthorizationFilter
I've used this and that link to secure my WebApi2 with tokens. When i authenticate it responds with something like this:
{
".expires": "Wed, 30 Jan 2019 14:14:44 GMT",
".issued": "Wed, 30 Jan 2019 13:44:44 GMT",
"access_token":…

Krzysztof
- 498
- 5
- 23
2
votes
1 answer
C# MailMessage with attachment breaks subject encoding
I'm sending e-mails with System.Net.Mail.SmtpClient. The problem is that when I add an attachment to the MailMessage the received e-mails subject and the attached filenames decoding goes wrong.
When the subject or attachment name string contains…

darph
- 29
- 5
2
votes
1 answer
method not found: System.Web.Http.Results.UnauthorizedResult
I'm writing some authentication logic in my Web API 2 app and I'm getting the error in the subject line. At first I was just returning Unauthorized() but then I got the error in the subject line. When I revisited the code I noticed that…

user9393635
- 1,369
- 4
- 13
- 32
2
votes
1 answer
Testing filters with IDependencyScope in Web API
I have WebApi simple NUnit Test
[Test]
public async Task Test()
{
var attribute = new TestAuthenticationAttribute {ApiVersions = new[] {"v1"}};
System.Web.Http.Controllers.HttpActionContext context = CreateExecutingContext();
var…

Oleg Makarenko
- 89
- 5
2
votes
1 answer
Azure appSettings / connectionStrings not transforming my web.config
I've followed what seemed to be a very straight forward setup to configure azure to transform my web.config but it isn't working as I expect. Here's what my web.config looks like locally.
Here's what my appSettings section looks like in the Azure…

Shane Drye
- 93
- 3
2
votes
1 answer
CORS - Delete and Put are not working,
I did all the setting,
Standerd web api config
Added all origins
AllowAnyMethod,AllowAnyHeader,SupportsCredentials,AllowAnyOrigin set to true
From IIS 7.5 delegation , set values to Read/Write
but still not able to make Delete and Put…

Amol Hegana
- 147
- 1
- 10
2
votes
3 answers
HTTP 405 Errors after Publishing Web API 2 Applications
I have a Web Api Controller and i have tested all actions on localhost and it works well.But when i Published it on Web Server,Just Actions with [HttpGet] works and [HttpPost] Actions return Http 405 error
public class ContentController :…

mohsen
- 1,763
- 3
- 17
- 55
2
votes
1 answer
User.Identity.IsAuthenticated always returns false
I'm implementing REST API using ASP.NET WEB API 2.I have default AccountController implementation with method for // GET…

Helga Lukava
- 21
- 1
- 4