asp.net-web-api2

DbContext is Disposed When Using Unity Dependency Injection on WebApi project

佐手、 提交于 2019-12-22 09:25:33
问题 I'm fairly new at using dependency injection and I think I must be overlooking something really simple. I have a Web API project where I'm registering generic repositories. The repositories take a dbContext as a parameter in their constructor. The behavior I find strange is that I can make one successfull call to the service but any subsequent calls tell me that the dbcontext has been disposed. I do have a using statement in there but that shouldn't be a problem since DI is supposed to be

Web API 2 AccessFailedCount not Incrementing When using Token Based Authentication

早过忘川 提交于 2019-12-22 08:48:13
问题 I am using Webapi with Identity2.0 AccessFailedCount, LockoutEndDateUtc is not incermenting on Invalid UserName and Password. I have implement Token Based Authentication provided by WebAPI. Please help . here is code Snippet using (UserManager<ApplicationUser> userManager = userManagerFactory) { ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password); if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } if

OWIN Authentication and Custom Response

ⅰ亾dé卋堺 提交于 2019-12-22 06:47:17
问题 I create a custom BasicAuthenticationMiddleware that use a BasicAuthenticationHandler to Authenticate requests from client to WebAPI. The BasicAuthenticationHandler derives from the AuthenticationHandler< TOptions > base class. Everything works fine and I implemented the AuthenticateCoreAsync where the logic to authenticate happens ApplyChallengeResponseAsync where the logic, in case of not authenticated requests, sends the WWW-Authenticate header to the client. What I would like to achieve

Do WebApi 2 and MVC 5 user different routing attributes?

↘锁芯ラ 提交于 2019-12-22 05:16:31
问题 Reading through this blog post on attribute routing in ASP.NET MVC 5 and this one on attribute routing in Web Api 2, it looks like there are two sets of routing attributes, one in the System.Web.Mvc namespace and the other in System.Web.Http . Is that right and does anyone have any idea (links) as to why it was designed this way? Should one be used over the other or are they supposed to live side by side? 回答1: Yes, these route attributes are intentionally different since Web API and MVC have

ModelState is always considered valid, regardless of null values in required fields

ε祈祈猫儿з 提交于 2019-12-22 04:09:34
问题 I've been looking around and I think my solution is just fine but somehow the ModelState.IsValid property is always true . Consider the following code snippets: [Route("address")] [HttpPut] [ResponseType(typeof(UserViewModel))] public IHttpActionResult UpdateAddress([FromBody] UpdateAdressValidationModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } // irrelevant code omitted } [TestMethod] public void UpdateAddress_WithoutStreet_ReturnsHttpCode400() { var

Web API Swagger documentation export to PDF

淺唱寂寞╮ 提交于 2019-12-22 03:58:53
问题 In according to the documentation (http://swagger.io/open-source-integrations/) there are plugins for Java to Export Swagger documentation to PDF , I just have a look the documentation but I can't see anything regarding .NET . My question is: is there something similar to the Java Plugin swagger2markup, swagger2markup-gradle-plugin in .NET or another way to export the PDF Documentation from WEB API? thanks 来源: https://stackoverflow.com/questions/40258287/web-api-swagger-documentation-export

Web Api HTTPPost not accepting int

▼魔方 西西 提交于 2019-12-22 03:47:21
问题 I am trying to just pass in body a int and it does not work Why do I need to create a class with a property of type int ? (then it works) WORKS [HttpPost] [Route("api/UpdateMainReversed")] public IHttpActionResult UpdateMainVerified(DataAccess.Entities.RequestMain mainValues) { ....} DO NOT WORK [HttpPost] [Route("api/UpdateMainReversed")] public IHttpActionResult UpdateMainVerified(int mainId) { ....} Testing with Postman http://localhost:13497/api/UpdateMainReversed Body { "mainId" : 1615 }

Different RoutePrefix, same controller name

陌路散爱 提交于 2019-12-22 01:39:20
问题 I'm having a problem with splitting my web-api application into different areas (not mvc areas), using namespaces and RoutePrefix The application is hosted using Owin Self Host, and in my Startup class I have the following. HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); app.UseWebApi(config); And my two controllers that I tested with [RoutePrefix("api/test")] public class TestController : ApiController { [Route("")] public IHttpActionResult Get() { return

Web Api 2 Post - UrlHelper.Link must not return null

流过昼夜 提交于 2019-12-22 01:24:05
问题 I have a basic web API 2 setup with some basic routing. Below is the default route and post for inserts. When I call the post the record is created perfectly in the database but the "CreatedAtRoute" call returns a 500 error stating: ExceptionMessage: "UrlHelper.Link must not return null." ExceptionType: "System.InvalidOperationException" Why would I receive this error? [RoutePrefix("api/casenotes")] public class CasenoteController : ApiController... // POST api/Casenote [Route("")]

How to pass Authorization token from one webapi to other webapi?

£可爱£侵袭症+ 提交于 2019-12-22 01:21:18
问题 I have configured two applications in Azure AD. One is a Web API called app-A and another is a Web API called app-B . how to I generate a token at app-A using client credentials token and pass that token to app-B ? 回答1: If I understand your question correct you want to forward Authorization token from one Web API service to another Web API? This is how I did it: Create a session context that exists within the request context. This is done by using Unity and HierarchicalLifetimeManager .