webapi2

Web API 2 - Method now allowed(405) for PUT

妖精的绣舞 提交于 2020-03-27 02:53:38
问题 I am stuck with Web API 2 controller, from which I call PUT method and it gives me an error that method isn't allowed. I added lines of code in Web.config that prevent WebDAV to block methods. I tried everything but it is not working. It is probably problem with my PUT method in a controller. Here is my controller code: public IHttpActionResult Put(int id, [FromBody]ArticleModel model) { var article = _articleService.UpdateArticle(model); return Ok<ArticleModel>(article); } This is a code

How do I resolve a WebAPI dependency in Autofac that requires a parameter from the route?

点点圈 提交于 2020-01-25 08:28:25
问题 I am struggling with wiring dependencies through autofac in my WebApi 2 project. I have a following interface and class that i'd like to inject in my GET and POST controller actions, public interface IRepository { IContext Context { get; } void SomeOperation(); } public MyRepository : IRepository { IContext _context; public MyRepository(IContext context) { _context = context; } public Context { get { return _context; } } public void SomeOperation { // Perform some operation using _context; }

Formarray doesnt show all the records received from service/api

送分小仙女□ 提交于 2019-12-25 03:16:22
问题 I am trying to patch the object received from webapi to an angular reactive form. The form also has a formarray. But, despite having more than 3 or more records only 2 records are being patched to the formarray of the reactive form. I have two entities noseries and noseriesList, where a noseries has zero or many noseriesLists. So after obtaining noseries from webapi, i want to patch properties and navigation list "noseriesLists" of noseries into reactive form. Rest of the properties are being

WebAPI .NET - POST request filter by parameters

和自甴很熟 提交于 2019-12-13 04:26:32
问题 I use POST to create messages and to update them (I need to use POST, not PUT). The API has the following instructions: POST /api/message POST /api/message?update_message How can I difference between both? Guess I have to do an if in the function: [HttpPost] [Route("api/message")] public async Task<HttpResponseMessage> Handle() {} checking if the request contains the parameter update_message. Any idea on how to solve that? Thanks. 回答1: A query string parameter has a key and a value. You

HTTP 405 Errors after Publishing Web API 2 Applications

淺唱寂寞╮ 提交于 2019-12-12 18:13:07
问题 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 : ApiController { [HttpGet] public async Task<IHttpActionResult> AdvantageList() { //return ok 200 } [HttpPost] public async Task<IHttpActionResult> SaveAdvantage(ContentModel model) { //return 405 } } I used below method on client var r = await ClientManager

GetAsync : not returning HttpResponseMessage

a 夏天 提交于 2019-12-11 13:45:41
问题 The apps should receive httpresponsemessage from LoginUser() but it becomes not responding. private void button1_Click(object sender, EventArgs e) { if (LoginUser(tUser.Text, Password.Text).Result.IsSuccessStatusCode) { Notifier.Notify("Successfully logged in.. Please wait!"); } else { Notifier.Notify("Please check your Credential.."); } } public async Task<HttpResponseMessage> LoginUser(string userid, string password) { string URI = "http://api.danubeco.com/api/userapps/authenticate"; using

using global exception handeling messes up DelegatingHandler

元气小坏坏 提交于 2019-12-08 07:33:51
问题 When ovveride the IExceptionHandler, the response does not reach the DelegatingHandler when a unexpected exception occurs. How can I fix this? In webapi 2, I want to implement a audit logger for request and response messages. I also want to add a global exception handler. However, when I replace the IExceptionHandler with my custom implementation. the response never reaches the DelegatingHandler -on exception - And thus the audit for response is lost. in WebApiConfig // add custom audittrail

using global exception handeling messes up DelegatingHandler

Deadly 提交于 2019-12-08 06:39:29
When ovveride the IExceptionHandler, the response does not reach the DelegatingHandler when a unexpected exception occurs. How can I fix this? In webapi 2, I want to implement a audit logger for request and response messages. I also want to add a global exception handler. However, when I replace the IExceptionHandler with my custom implementation. the response never reaches the DelegatingHandler -on exception - And thus the audit for response is lost. in WebApiConfig // add custom audittrail logger config.MessageHandlers.Add(new AuditLogHandler()); // replace global exception handeling config

Handling JWT token in multiple services

可紊 提交于 2019-12-08 06:01:44
问题 I'm working on a system where it access few rest APIs and we use JWT toke based authentication. Is it possible to use same token across all services ? If yes, how 回答1: Token can be used (by "used", I mean consumed) across different services as long as they use the same token provider to validate the token. In fact, token is supposed to be short-lived for security purpose. So in real, you will just use one-time token to establish the user session. And based on the user session, you will do

How to generate documentation using swashbuckle for WebApi 2 with Owin

走远了吗. 提交于 2019-11-29 23:49:12
问题 I have created a WebApi Project using this article. Things are working fine. But now my client want to view the documentation using Swagger. I tried to do configuration but things are not working. not getting the list of controllers and their action. below is the swagger config: using System.Web.Http; using WebActivatorEx; using DC.SUMS.WebAPI1; using Swashbuckle.Application; using System; using System.Linq; using Swashbuckle.Swagger; using Swashbuckle.Dummy.SwaggerExtensions; [assembly: