asp.net-web-api2

Web API 405 Method Not Allowed In Remote

筅森魡賤 提交于 2019-12-11 20:36:34
问题 Following is one my action: public IHttpActionResult PutUnit(int id, Unit unit) { if (!ModelState.IsValid) return BadRequest(ModelState); if (id != unit.UnitId) return BadRequest(); db.Entry(unit).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UnitExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); } Following is the response I get: Date: Tue, 19 Aug 2014 10:30:31 GMT Server: Microsoft-IIS/8.5 X

Unable to inject with unity a complex type to web api 2

心已入冬 提交于 2019-12-11 20:15:43
问题 I have a complex type to inject into a webapi controller and I am unable to resolve this dependency public class MyController(IMyComplexType) The implementation of IMyComplexType has at least 5 dependencies I1, ... I5 (so its implementation recieve I1...I5 ) I have a Bootstrapper class to Register all dependencies, below a snippet of code to show you public class Bootstrapper { public static IUnityContainer ConfigureContainer(ref IUnityContainer container) { container.RegisterType

How to pass query string parameter to asp.net web api 2

女生的网名这么多〃 提交于 2019-12-11 18:28:52
问题 How can I pass more than 1 parameters as part of query string to my asp.net web api 2. This is my asp.net web api 2 method, I am not able to figure out that how can I decorate this method so that it accepts the id and a complex type which is CustomerRequest, I want to use Url something like http://localhost/api/Customer/?Mobile0012565987&Email=abcxyz.com&IsEmailVerified=true [ResponseType(typeof(Customer))] public IHttpActionResult GetCustomer(long id, [FromUri]CustomerRequest request) { var

How to validate only a part of Model State in asp.net core 2 web api

社会主义新天地 提交于 2019-12-11 17:53:31
问题 We are using a Usermaster DTO in 2 different projects. public class UserMaster : BaseProperties { [BsonElement] [BsonRequired] [Required] public string FirstName { get; set; } [BsonElement] [BsonRequired] [Required] public string LastName { get; set; } [BsonElement] [BsonRequired] [EmailAddress] [Required] public string EmailId { get; set; } [BsonElement] [BsonRequired] [DataType(DataType.Password)] [Required] public string Password { get; set; } [BsonIgnore] [DataType(DataType.Password)]

WebAPI 2 not deserializing List<string> property of FromBody object in POST request

有些话、适合烂在心里 提交于 2019-12-11 17:53:23
问题 In one of my WebAPI 2 applications, I'm having trouble deserializing a List<string> property of a FromBody object. (The list stays empty, while the other properties are deserialized correctly.) Whatever I do, the property only seems to deserialize correctly if I change the property to a string[] . Unfortunately for me, the property needs to be of type List<string> . According to another question I found, I should be able to deserialize to a List<T> , as long as T is not an Interface . Is

Model normalization before model validation in Asp.Net Core 2.0+

人走茶凉 提交于 2019-12-11 17:40:06
问题 I'm using automatic model validation (see "Better Input Processing") to keep my controllers clean; so: [HttpPost] [ProducesResponseType(typeof(Product), 201)] public IActionResult Post([FromBody] Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } product = _repository.AddProduct(product); return CreatedAtAction(nameof(Get), new { id = product.Id }, product); } becomes: [HttpPost] [ProducesResponseType(201)] public ActionResult<Product> Post(Product product) {

Injecting ISecureDataFormat in Web API 2 AccountController using Autofac

房东的猫 提交于 2019-12-11 16:28:45
问题 I am using ASP.NET Identity 2.2 in a Web API 2 project but I am unsure how to wire up the ISecureDataFormat<AuthenticationTicket> dependency of the AccountController using Autofac . I tried this: builder.RegisterType<ISecureDataFormat<AuthenticationTicket>>() .As<TicketDataFo‌​rmat>(); and getting error: The type 'Microsoft.Owin.Security.ISecureDataFormat`1[Microsoft.Owin.Security.Authenticat‌​ionTicket]' is not assignable to service 'Microsoft.Owin.Security.DataHandler.TicketDataFormat' None

Web API OData ignore properties added by client-side

时光总嘲笑我的痴心妄想 提交于 2019-12-11 16:08:31
问题 I get an error when I call Put to my server using WebApi Odata v4. { "error": { "code": "", "message": "The request is invalid.", "innererror": { "message": "job : The property 'test' does not exist on type 'Model.Temp'. Make sure to only use property names that are defined by the type.\r\n", "type": "", "stacktrace": "" } } } this error happens because the property "test" is not set in the Model "Temp". it is actually added by javascript, and only used in client-side How do I make so that

How to limit user to only one access token in ASP.NET Identity

蹲街弑〆低调 提交于 2019-12-11 14:03:52
问题 I'm Using Token-Based Authentication in my webApi application. for each login OAuth generates an access token for user. if a user tries to do login more than once. it may own some more valid token. is there a limitation on this process. Here is my Startup class: public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); ConfigureOAuth(app); WebApiConfig.Register(config); app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); app.UseWebApi(config); //Rest

$Search not working in odata web api 2

三世轮回 提交于 2019-12-11 13:13:53
问题 I am unable to determine how to get $search parameter to work for full text search in odata. The following url indicates that it should be included in 6.1 http://blogs.msdn.com/b/odatateam/archive/2014/03/21/odata-6-1-and-odata-client-6-1-are-now-shipped.aspx I have created a sample application using the following template http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint When I execute the odata query http://localhost:53621/odata