asp.net-web-api2

How to get object using Httpclient with response Ok in Web Api

纵然是瞬间 提交于 2019-11-30 18:11:56
my web api like public async Task<IHttpActionResult> RegisterUser(User user) { //User Implementation here return Ok(user); } I am using HTTPClient to request web api as mentioned below. var client = new HttpClient(); string json = JsonConvert.SerializeObject(model); var result = await client.PostAsync( "api/users", new StringContent(json, Encoding.UTF8, "application/json")); Where i can find user object in my result request which is implemented on client application? You can use (depands on what you need), and de-serialize it back to user object. await result.Content.ReadAsByteArrayAsync(); /

Web API 2 - Implementing a PATCH

我怕爱的太早我们不能终老 提交于 2019-11-30 17:52:34
I currently have a Web API that implements a RESTFul API. The model for my API looks like this: public class Member { public string FirstName { get; set; } public string LastName { get; set; } public DateTime Created { get; set; } public DateTime BirthDate { get; set; } public bool IsDeleted { get; set; } } I've implemented a PUT method for updating a row similar to this (for brevity, I've omitted some non-relevant stuff): [Route("{id}")] [HttpPut] public async System.Threading.Tasks.Task<HttpResponseMessage> UpdateRow(int id, [FromBody]Models.Member model) { // Do some error checking // ... /

Loading Image in JavaScript with Bearer token

安稳与你 提交于 2019-11-30 17:51:26
问题 I am loading an image in JS like this: var img = new Image(); img.onload = function () { .. }; img.src = src; This will work, but I have realized that I must secure my images on the server side with OAuth 2 (as with the rest of the application) and this will effect in me simply receiving a 401 Unauthorized. This is an angular app and I do have an interceptor adding the Authorization header consequently for all the angular service requests to the server, but in this case of course - the

Leverage MultipleApiVersions in Swagger with attribute versioning

拟墨画扇 提交于 2019-11-30 16:55:21
问题 Is it possible to leverage MultipleApiVersions in Swagger UI / Swashbuckle when using attribute routing? Specifically, I implemented versioning by: using System.Web.Http; namespace RESTServices.Controllers.v1 { [Route("api/v1/Test")] public class TestV1Controller : ApiController { ... } Version 2 would be in a v2 namespace. In a controller named TestV2Controller. The route would have v2 in it. Is it possible to pass a lambda in that will allow this? I found a sample lambda online which

Design of Application in Azure Service Fabric

拥有回忆 提交于 2019-11-30 15:22:29
问题 I need help how to think about designing our application to fit into the new Azure Service Fabric template. Today we have an application built on Azure Cloud Services. The application is built around DDD and we have separate bounded contexts for different subsystem parts of the application. The bounded contexts are today hosted in one worker role that exposes these subsystems using a single WebAPI. Additionally we have one Web Role hosting the web frontend and one Worker Role processing a

Design of Application in Azure Service Fabric

断了今生、忘了曾经 提交于 2019-11-30 14:01:48
I need help how to think about designing our application to fit into the new Azure Service Fabric template. Today we have an application built on Azure Cloud Services. The application is built around DDD and we have separate bounded contexts for different subsystem parts of the application. The bounded contexts are today hosted in one worker role that exposes these subsystems using a single WebAPI. Additionally we have one Web Role hosting the web frontend and one Worker Role processing a background queue. We strive to move to a micro services architecture. The first thing I planned to do was

How can I limit the serving of a javascript file to only authenticated users?

核能气质少年 提交于 2019-11-30 13:43:17
I have a WebAPI 2 / AngularJS SPA application that uses Identity 2 for authentication. Locally my code stores a token for authentication. I would like to implement functionality that allows my application to request additional javascript for authenticated users after my initial index.html page has been downloaded. Is there a way I can make my server code give out the javascript files to only authenticated and authorized users? Something similar to the way a controller action method returns data to only authenticated and authorized users. Dalorzo You can force the static files to go through the

Post JSON string to WEB API

老子叫甜甜 提交于 2019-11-30 13:28:08
I have an ASP.NET WEB-API 2 app witch needs to have a POST method that accepts a JOSN string with unknown structure from javascript . I enabled cors and GET methods works fine, however when sending JSON from the client the api's method parameter is always null . This is my api method: //parameters i tried: //[FromBody]string model //[FromBody]dynamic model //dynamic model public HttpResponseMessage Post(string model) { return new HttpResponseMessage() { Content = new StringContent("POST: Test message: " + model) }; } and my client method: function sendRequest() { var Test = {"Name":"some name"

Controlling what is returned with an $expand request

末鹿安然 提交于 2019-11-30 13:03:00
So, using the ODataController , you get to control what gets returned if somebody does /odata/Foos(42)/Bars , because you'll be called on the FoosController like so: public IQueryable<Bar> GetBars([FromODataUri] int key) { } But what if you want to control what gets returned when somebody does /odata/Foos?$expand=Bars ? How do you deal with that? It triggers this method: public IQueryable<Foo> GetFoos() { } And I assume it just does an .Include("Bars") on the IQueryable<Foo> that you return, so... how do I get more control? In particular, how do I do it in such a way that OData doesn't break

ASP.NET API versioning

六眼飞鱼酱① 提交于 2019-11-30 10:24:52
I'm new to ASP.NET but I'm looking to implement some versioning for a new API I'm about to start. I'm not even sure if what I'm looking for is possible but I'm after a very clean version method using a header variable. Ideally I want to be able to have a versions folder within the code structure and different folders containing the different API versions within that. Each version folder would contain a full copy of the core API code so I'd know there would never be any conflicts etc. I know this would inflate the code but it's worth to keep it very clean and there would only be over 2-3