asp.net-web-api2

Web API 2 REST Get() not receiving parameters: Angular

旧巷老猫 提交于 2019-12-12 06:57:01
问题 I am having a problem with my REST Get() method. I am calling it with parameters from my AngularJS controller but the id parameter is not being populated correctly. Here is my Web API 2 controller: public IEnumerable<string> Get(SearchParameters id) { // not important at the moment return null; } public struct SearchParameters { string selectedBroker; string brokerIsUnallocated; string brokerIncludeDeleted; string customerId; string businessType; string companyName; string town; string

openid: create claim based authorization attribute

为君一笑 提交于 2019-12-12 06:38:19
问题 I have implemented SSO to my api ( web-api 2 ) and it's validating correctly the token. But now I have to add a claim based authorization attribute. In the access token I have: "MyClaim.Read.All": "true" And I would like to achieve something like: [ClaimAuthorizationAttribute("MyClaim.Read.All")] public sealed class MerchantProfileController : ApiController So that if the token doesn't contain this claim, I would give a 401 error. How to achieve this, so I can use this attribute to any

Does Task.Factory.StartNew has any performance side effects?

只谈情不闲聊 提交于 2019-12-12 06:14:34
问题 I'm catching and logging exceptions in an ASP.NET Web API 2 app by starting a new thread to log: void MainMethod(){ try{ // stuff... } catch (Exception ex) { Logger.Log(ex); } } class Logger { void Log(Exception ex) { Task.Factory.StartNew(() => LogAsync(ex)); } void LogAsync(Exception ex) { // doing some reflection stuff to retrieve code-place // saving the log... } } The question is: in a real high traffic app, does this approach has any side effects? Is it better to log in the main context

Update and Delete does not work in jqGrid

北慕城南 提交于 2019-12-12 05:25:29
问题 I am working on web api project and I want implement grid with CRUD operations. These are my web api methods: [HttpGet] public HttpResponseMessage GetAllPosting() {} [HttpGet] public HttpResponseMessage GetPostingById(int Id) {} [HttpPost] public HttpResponseMessage Post([FromBody] vGeneralLedger item) {} [HttpPut] public HttpResponseMessage Put(int id, vGeneralLedger item) {} [HttpDelete] public void Delete(int id) {} In my view page, I am defined jQgrid: jQuery("#generalLedgerGrid").jqGrid(

RoutePrefix Order alternative for WebAPI 2

十年热恋 提交于 2019-12-12 04:56:51
问题 In WebAPI you can specify an Order in RouteAttribute to determine which order the routes are matched in. For example the below will match /other to GetOther before matching /blah to GetByName [HttpGet, Route("{name}", Order = 1)] public string GetByName(string name) { ... } [HttpGet, Route("other")] public string GetOther() { ... } How would I do the same but with RoutePrefix (which doesn't have an Order property)? If it did it would looks something like this: [RoutePrefix("foo", Order = 1)]

How do you setup mixed authorizations for different authentications in .net (web api 2 + owin)

天大地大妈咪最大 提交于 2019-12-12 04:12:43
问题 I am fairly new to .net and I am trying to create a restfull service where you can authenticate via OAuth2 to a service like facebook and also be able to login with a "normal account". The SPA template from VS2013 allowed me to do this quickly and easily and I am very happy with it. Right now I am facing a different problem. I can't seem to find a way to separate access for these different types of logins. For example, I want to allow only users from the oauth authentication method to access

OperationContext.Current and HttpContext.Current are null in OWIN hosted Web API 2

谁说我不能喝 提交于 2019-12-12 03:57:06
问题 I am moving some of WCF services to the Web API. OperationContext.Current is usually used in WCF for logging and staging purposes. But i'm seeing HttpContext.Current and OperationContext.Current as null. I have used a framework which uses OperationContext.Current to get the execution context for the current thread. So if i am opting for other ways, i have to add my custom method to the framework, which i am trying to avoid. Questions: What is the workaround that i can adopt? If "adding to

OData aggregate query with Count

独自空忆成欢 提交于 2019-12-12 03:48:49
问题 In odata 5.3.1 the aggregate query was not working so that I wrote my custom facet class to get aggregate count of items. http://localhost/odata/Document$apply=groupby((Category),%20aggregate(Document/$count%20as%20Total)) But in Odata 5.9.1 the above query is failing as because it has already aggregate function included. So for my custom method it is not working. GithHub aggregate function I want data something like this : "value": [ { "name" : "doc1", "version" 2: , "total": 5 }, { "name" :

Parsing Json .Net Web Api

时光怂恿深爱的人放手 提交于 2019-12-12 03:44:41
问题 I'm new with Web API 2 / Entity Framework 6 project, I'm making REST services, but for one specific service I'm going to receive (via Post) a JSON before making any CRUD operations over any entity of the model, (have to make some business validations over the data, add or complement some things and decide on wich entity to save), the JSON is: { "head": { "action": "create", "object": "oneobject", "user": "theuser" }, "object": { "name1": "a name 1", "name2": "a name 2", "description": "a

Set WebApi 2 routes

我是研究僧i 提交于 2019-12-12 03:29:51
问题 I'm fairly new to WepApi2 and creating restfull webservice, but I get the hang of most of it. Recently, I started developing a new WebApi2 where I encounter that some of my queries required some unesacapable characters, specially the slash and inverted slash ones. I read several tutorials and questions here about the matter, but none would suffice me, so I ended up to setting my api queries like this http://host/controler/action/?param1=x&param2=y Everything works perfect. I had to setup the