asp.net-web-api2

Breeze filtering .Expand on server side

只愿长相守 提交于 2019-12-01 23:16:09
I'm trying out BreezeJS . There is a requirement that I can use .expand in the client side code, but based on the role of the user, the server side will not return all the records for the .expand requested type. I tried to create a custom BreezeQueryable attribute and override a method to completely filter out the extra data first just to try. But it threw an exception. I don't see any entry point where I can do that on the server side. Please guide me in the right direction, or let me know if that's not possible. I only have access to generic IQueryable , how do I perform queries on this?

.NET WebApi breaks when url ends with ampersand

孤街浪徒 提交于 2019-12-01 22:09:00
I have an ApiController - for example 'Home' controller, with action 'Test' which accepts two parameters - test1 and test2, both with default values [System.Web.Http.HttpGet] public ActionResult Test(int test1 = 3, int test2 = 5) { var a = 0; return null; } Now when I call Home/Test?test1=1 , everything is OK. But when I call Home/Test?test1=1& , the server throws exception The parameters dictionary contains a null entry for parameter 'test2' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Test(Int32, Int32)' in 'TestAPI.Controllers.ValuesController'. An optional

Different Models for RESTful GET and POST

断了今生、忘了曾经 提交于 2019-12-01 21:42:00
Does it violate the ideas of REST, or accepted conventions, to have different models for GET/PUT/POST at the same URL? An example: Consider a simple resource found at api/things I can create a thing by: POST api/things with body = { Name: "New Thing" } This returns me a thing along with location { Id: 500, Name: "New Thing", Links: ["api/things/500"] } Location Header: api/things/500 I can get the thing with: GET api/things/500 and I will get { Id: 500, Name: "New Thing", Links: ["api/things/500"] } If I want to update it: PUT api/things/500 { Name: "Updated Thing", IsActive: false } There are

AuthorizationCodeProvider: Create is never called, how do I generate the authorization code?

≡放荡痞女 提交于 2019-12-01 21:17:21
I'm setting up my own OAuth2 server. So far, I have succesfully implemented GrantResourceOwnerCredentials in my implementation of OAuthAuthorizationServerProvider . Now, because I am developing an app for our business, I want to implement the OAuth2 Authorization Code grant. I have tried to follow directions here https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-server but in my implementation, I have not found how to reach the Create call of the AuthorizationCodeProvider (which I set in OAuthAuthorizationServerOptions ). I have briefly checked

Web API 2: OData 4: Actions returning 404

时光毁灭记忆、已成空白 提交于 2019-12-01 20:38:18
I have an OData v4 action method which is not working; note however that it was working fine in OData v3 (I am obviously in the process of trying to update my project) OData Action Method: [HttpPost] public Translation Translate(ODataActionParameters parameters) { // Implementation } Configuration: ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<Page>("Pages"); //etc (Other Entity Sets) var pageEntityType = builder.EntityType<Page>(); var translateAction = pageEntityType.Collection.Action("Translate"); translateAction.Parameter<Guid>("pageId"); translateAction

WebApi2 IHttpActionResult strongly typed return values

一笑奈何 提交于 2019-12-01 17:18:07
问题 It is possible and not ideal to do this: (a vastly simplified example!) [Serializable] public class MyRecord { public string key {get; set;} public string data {get; set;} } public async Task<IHttpActionResult> Get(string SomeKey) { if(ExistsInDB(SomeKey)) { return Ok(SomeRecordFromDB(SomeKey)); //SomeRecord() returns a POCO MyRecord. } else { //I know I can return NotFound() but not the focus of my Q return Ok(false); //returns "False" } } Effectively demonstrating no compile time error

Multiple optional query string parameters REST API GET

ぐ巨炮叔叔 提交于 2019-12-01 16:09:32
I am using web api 2 to implement a restful service. After doing some research on best practices everyone seems like they are having different opinions on how to do the following. I have a GET public HttpResponseMessage Get(string crewId, string shiftDate, int offset = 1, int limit = 10) This GET method returns a list. There are multiple ways of getting the data from this method. Get by crewId only Get by shiftDate only or Get by crewId and shiftDate Do you (1) Mark the crewId and shiftDate as optional? public HttpResponseMessage Get(string crewId = null, string shiftDate = null, int offset =

Multiple optional query string parameters REST API GET

谁说我不能喝 提交于 2019-12-01 15:22:00
问题 I am using web api 2 to implement a restful service. After doing some research on best practices everyone seems like they are having different opinions on how to do the following. I have a GET public HttpResponseMessage Get(string crewId, string shiftDate, int offset = 1, int limit = 10) This GET method returns a list. There are multiple ways of getting the data from this method. Get by crewId only Get by shiftDate only or Get by crewId and shiftDate Do you (1) Mark the crewId and shiftDate

How I can bypass “angular-in-memory-web-api” for a specific url

北战南征 提交于 2019-12-01 15:10:06
问题 I was using "angular-in-memory-web-api" to mock my REST web api, however now I am have started writing the actual web api and I want to replace the "angular-in-memory-web-api" step by step. Example: I have written following asp.net web api /api/values however when I issue http.get() request using above api url angular tries to serve it using "angular-in-memory-web-api", however in this case I want to bypass "angular-in-memory-web-api" so that request is entertained by my actual web api

webapi, how to read the file from a POST/PUT action with custom model binder

女生的网名这么多〃 提交于 2019-12-01 14:08:34
I have the following react component, which apparently its working fine: import React, { Component } from 'react'; import { Row, Col } from 'antd'; import PageHeader from '../../components/utility/pageHeader'; import Box from '../../components/utility/box'; import LayoutWrapper from '../../components/utility/layoutWrapper.js'; import ContentHolder from '../../components/utility/contentHolder'; import basicStyle from '../../settings/basicStyle'; import IntlMessages from '../../components/utility/intlMessages'; import { adalApiFetch } from '../../adalConfig'; export default class extends