asp.net-web-api

Make names of named tuples appear in serialized JSON responses

好久不见. 提交于 2020-12-28 13:20:41
问题 Situation : I have multiple Web service API calls that deliver object structures. Currently, I declare explicit types to bind those object structures together. For the sake of simplicity, here's an example: [HttpGet] [ProducesResponseType(typeof(MyType), 200)] public MyType TestOriginal() { return new MyType { Speed: 5.0, Distance: 4 }; } Improvement : I have loads of these custom classes like MyType and would love to use a generic container instead. I came across named tuples and can

Make names of named tuples appear in serialized JSON responses

倖福魔咒の 提交于 2020-12-28 13:13:31
问题 Situation : I have multiple Web service API calls that deliver object structures. Currently, I declare explicit types to bind those object structures together. For the sake of simplicity, here's an example: [HttpGet] [ProducesResponseType(typeof(MyType), 200)] public MyType TestOriginal() { return new MyType { Speed: 5.0, Distance: 4 }; } Improvement : I have loads of these custom classes like MyType and would love to use a generic container instead. I came across named tuples and can

Make names of named tuples appear in serialized JSON responses

早过忘川 提交于 2020-12-28 13:13:15
问题 Situation : I have multiple Web service API calls that deliver object structures. Currently, I declare explicit types to bind those object structures together. For the sake of simplicity, here's an example: [HttpGet] [ProducesResponseType(typeof(MyType), 200)] public MyType TestOriginal() { return new MyType { Speed: 5.0, Distance: 4 }; } Improvement : I have loads of these custom classes like MyType and would love to use a generic container instead. I came across named tuples and can

Autofac injection of IHubContext SignalR MVC

一曲冷凌霜 提交于 2020-12-26 08:09:33
问题 I am trying to get SignalR working with Autofac. I have a repo of a stripped back version of what I have done here: https://github.com/justsayno/signalr-autofac This is adapted from which works using GlobalHost : https://github.com/sstorie/experiments/tree/master/angular2-signalr That works just fine using hte GlobalHost object. I have attempted to follow the documentation on Autofac's site about how to inject SignalR services but I cannot get it to work. This is my config file for

Supporting multiple languages in a REST API

给你一囗甜甜゛ 提交于 2020-12-26 08:03:13
问题 I have a collection of cities for which I'm creating a REST API (my first REST API). Each city has a number of language independent things, such as founding date and population count. Cities also have things that depend on the language, such as the title and a short description. Internally the city documents have this format: { "population": 9042, "name": { "en": "Berlin", "nl": "Berlijn", // ... }, // ... } The users of my API always want to view the city info for a specific language only,

Combining cookie and token authentication in ASP.NET Core

你说的曾经没有我的故事 提交于 2020-12-15 06:22:06
问题 I've REST services (Web API) and admin panel (MVC) in one project on ASP.NET Core 2.1. I want to secure my API with JWT token, and my MVC pages with cookies. Can I combinate these two authentication ways. How to configure my Startup.cs, Authorize attribute and sign in functionality. 回答1: I suppose you should use an OAuth 2.0 framework. please check IdentityServer4 it enables many features in your applications. IdentityServer is middleware that adds the spec compliant OpenID Connect and OAuth

Object null in WebApi method after PostAsJsonAsync

寵の児 提交于 2020-12-14 06:54:45
问题 I am posting an object to a WebApi method. I'm using PostAsJsonAsync to do this. public async Task<HttpResponseMessage> PostAsync(string token, ServiceCall call) { var client = new HttpClient(); client.SetBearerToken(token); var response = await client.PostAsJsonAsync(Uri + "id/nestedcall", call); return response; } The object call that I'm passing is not null when I post it. [HttpPost] [Route("id/nestedcall")] public async Task<IHttpActionResult> NestedCall([FromBody]ServiceCall call) { //

Object null in WebApi method after PostAsJsonAsync

◇◆丶佛笑我妖孽 提交于 2020-12-14 06:52:04
问题 I am posting an object to a WebApi method. I'm using PostAsJsonAsync to do this. public async Task<HttpResponseMessage> PostAsync(string token, ServiceCall call) { var client = new HttpClient(); client.SetBearerToken(token); var response = await client.PostAsJsonAsync(Uri + "id/nestedcall", call); return response; } The object call that I'm passing is not null when I post it. [HttpPost] [Route("id/nestedcall")] public async Task<IHttpActionResult> NestedCall([FromBody]ServiceCall call) { //

Inject SignalR IHubContext into service layer with Autofac

霸气de小男生 提交于 2020-12-09 06:34:32
问题 In an app running Framework 4.72, not .NET Core, I'm trying to inject a SignalR IHubContext into a Web API 2.x service. I have my solution broken into three projects, web, service, data. The SignalR hub is in the web layer. I have background code that runs in the service layer and when complete I need it to send a mesage via the hub. This background task is not initiated by the controller. My Global.asax is pretty standard: protected void Application_Start() { GlobalConfiguration.Configure

Generate Reset Password link in WebApi

爷,独闯天下 提交于 2020-12-08 05:29:21
问题 I wanted to generate a reset password link to send to the user's email that will open the ResetPassword page. On this page I will fill in the details regarding the new password and then confirm the password. For this I have followed this Link But there is a Url.Action method that i am not able to find in my web api project. var callbackUrl = Url.Action( "ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); Hase anybody done the reset password part in