asp.net-web-api2

ionic app cannot connect cors enabled server with $http

折月煮酒 提交于 2019-12-17 09:51:43
问题 I am trying to build a mobile app with ionic framework. When my application tries to connect server to get json ( server is web api and cors is enabled) it just returns 404 on genymotion and real device. But when I run application in browser with ionic serve everything work fine. I am pretty sure CORS is functional. Here response header I got while application working in browser. Response Access-Control-Allow-Origin:* Cache-Control:no-cache Content-Length:395 Content-Type:application/json;

ionic app cannot connect cors enabled server with $http

你离开我真会死。 提交于 2019-12-17 09:51:08
问题 I am trying to build a mobile app with ionic framework. When my application tries to connect server to get json ( server is web api and cors is enabled) it just returns 404 on genymotion and real device. But when I run application in browser with ionic serve everything work fine. I am pretty sure CORS is functional. Here response header I got while application working in browser. Response Access-Control-Allow-Origin:* Cache-Control:no-cache Content-Length:395 Content-Type:application/json;

Newtonsoft JSON dynamic property name

那年仲夏 提交于 2019-12-17 07:33:34
问题 Is there a way to change name of Data property during serialization, so I can reuse this class in my WEB Api. For an example, if i am returning paged list of users, Data property should be serialized as "users", if i'm returning list of items, should be called "items", etc. Is something like this possible: public class PagedData { [JsonProperty(PropertyName = "Set from constructor")]?? public IEnumerable<T> Data { get; private set; } public int Count { get; private set; } public int

Order of execution with multiple filters in web api

若如初见. 提交于 2019-12-17 07:10:16
问题 I am using latest web api . I do annotate some controllers with 3 different filter attributes. 1 [Authorize] 2 [RessourceOwnerAttribute derived from AuthorizationFilterAttribute] 3 [InvalidModelStateAttribute derived from ActionFilterAttribute] I can not be sure that the filters run in the order they are declared from top to down. How do I define the order of execution in web api 2.1 ? https://aspnetwebstack.codeplex.com/workitem/1065# http://aspnet.uservoice.com/forums/147201-asp-net-web-api

MVC-Web API: 405 method not allowed

眉间皱痕 提交于 2019-12-17 06:46:37
问题 So, I am stuck in a strange behavior, that is, I am able to send(or POST) data using Postman (plugin of chrome) or using RESTClient(extension of Firefox) , but not able to send it from my html file which lies outside the project. It shows following error when i open the html in chrome: OPTIONS http://localhost:1176/api/user/ 405 (Method Not Allowed) XMLHttpRequest cannot load http://localhost:1176/api/user/. Invalid HTTP status code 405 I am not able to make out why is this happening.

asp.net MVC Custom Filters [RESTAuthorize] is ignored

别说谁变了你拦得住时间么 提交于 2019-12-14 03:57:02
问题 The [RESTAuthorization] is being ignored and instead jump into the code to Get all the Country without checking for the Rest Authorization filter. Here is the code for RESTAuthorization using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MyWebsite.Repository; namespace MyWebsite.API.Attributes { public class RESTAuthorizeAttribute : AuthorizeAttribute { private ISecurityRepository _repository; public RESTAuthorizeAttribute() : this

Connect Angular routing with MVC routing

戏子无情 提交于 2019-12-14 03:15:43
问题 In my new project in WebApi2 I use Angular2 framework. After configuring and adding angular I tried to call first compnent. And there is my question. How to connect angular routing with webapi2? I add new class where I add routing: I call <home-page> in MVC controller view Index.cshtml app.routing.ts const appRoutes: Routes = [ { path: 'home', component: HomePage }, { path: 'test', component: AppComponent} ]; app.component.ts @Component({ selector: 'my-app', templateUrl: './app.template.html'

Allow .NET WebApi to disregard DOCTYPE declaration

余生长醉 提交于 2019-12-14 02:59:12
问题 I am trying to deserialize XML to an object through a WebApi Method. I have the following class: [XmlRoot(IsNullable = false)] public class MyObject { [XmlElement("Name")] public string Name {get;set;} } And the following Method in a WebApi Controller. [HttpPost] public HttpResponseMessage UpdateMyObject(MyObject model) { //do something with the model } I am using the XmlSerializer by setting the following in the startup of the Web Project: config.Formatters.XmlFormatter.UseXmlSerializer =

Consuming WEB API REST GET Xamarin Forms

别等时光非礼了梦想. 提交于 2019-12-13 22:40:15
问题 I have a WEB API hosted on a server, there I have a Products table with Name and Description.I already checked for the postman and this is ok, when I try to implement the method in xamarin by visual studio to bring a record by its name and display in a listview I can not. Could someone help me in the code private async void GetProductByName(string Name) { using (var client = new HttpClient()) { txtTest.Text = "http://www.ProdutosAPITest6.hostname.com/api/products"; var URI = txtTest.Text + "/

How to implement WebApi custom model binder

旧城冷巷雨未停 提交于 2019-12-13 19:41:56
问题 I am implementing custom model binder. I researched how to do it and found out that in case of WebApi I need to implement IModelBinder interface. My implementation looks like this: public class ModelBaseBinder : IModelBinder { public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) { if ((bindingContext.Model is MyModel)) { //my code here controller.InitModel(model); return true; } return false; } } I am just not sure if my implenentaton is complete. Do I