asp.net-web-api

OWIN Security - How to Implement OAuth2 Refresh Tokens

元气小坏坏 提交于 2020-01-05 08:11:54
问题 I am using the Web Api 2 template that comes with Visual Studio 2013 has some OWIN middleware to do User Authentication and the likes of. In the OAuthAuthorizationServerOptions I noticed that the OAuth2 Server is setup to hand out tokens that expire in 14 days OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString("/api/token"), Provider = new ApplicationOAuthProvider(PublicClientId,UserManagerFactory) , AuthorizeEndpointPath = new PathString("/api/Account

Posting multiple content types to web api

被刻印的时光 ゝ 提交于 2020-01-05 08:08:22
问题 I have a web api and I would like to post an image file + some data in order to process it correctly when it is received at the server. The calling code looks something like this: using(var client = new HttpClient()) using(var content = new MultipartFormDataContent()) { client.BaseAddress = new Uri("http://localhost:8080/"); var fileContent = new ByteArrayContent(File.ReadAllBytes(fileName)); fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue(

Posting multiple content types to web api

*爱你&永不变心* 提交于 2020-01-05 08:07:19
问题 I have a web api and I would like to post an image file + some data in order to process it correctly when it is received at the server. The calling code looks something like this: using(var client = new HttpClient()) using(var content = new MultipartFormDataContent()) { client.BaseAddress = new Uri("http://localhost:8080/"); var fileContent = new ByteArrayContent(File.ReadAllBytes(fileName)); fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue(

dotnet core no overload method for UseInMemoryDatabase() takes 0 argument

雨燕双飞 提交于 2020-01-05 05:38:06
问题 I am trying dotnet core tutorial at https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-vsc TodoContext.cs using Microsoft.EntityFrameworkCore; namespace TodoApi.Models { public class TodoContext : DbContext { public TodoContext(DbContextOptions<TodoContext> options) : base(options) { } public DbSet<TodoItem> TodoItems { get; set; } } } Startup.cs using ... using TodoApi.Models; using Microsoft.EntityFrameworkCore; namespace TodoApi { public class Startup { public Startup

How can I get a list of playlists by user with the spotify web api?

旧巷老猫 提交于 2020-01-05 05:35:09
问题 I'm working on a project and I would like to get a list of all the playlists of the logged in user on spotify. Currently I can loggin and see user info (by following the demo on spotify). Now I want to get the playlists of the user that is logged in and that is where I'm stuck. This is the code I have: /** * This is an example of a basic node.js script that performs * the Authorization Code oAuth2 flow to authenticate against * the Spotify Accounts. * * For more information, read * https:/

Should I be using my own Web API

烂漫一生 提交于 2020-01-05 04:38:30
问题 I'm checking out Web API and I'm not sure how asp.net mvc and web api can or should work together. I want to implement Backbone on the client side, but I'm not sure if I should implement an ApiController or a normal Controller on the server side? The way I'm doing things (Getting current user / account information) is that a base ApiController will have some of the same functionality as a base Controller would, which would lead to a bit of duplicate functionality, but not sure what would be

Issue loading events Fullcalendar.io

别等时光非礼了梦想. 提交于 2020-01-05 04:17:09
问题 We are using fullcalendar.io and we want to get an event from our api controller. Our Controller [Route("api/Bookings")] public class BookingApiController { // GET [HttpGet] public string Get() { var returnJson = new { events = new[] { new {title = "bro", start = "2018-05-06"}, new {title = "bro2", start = "2018-05-05"} } }; return JsonConvert.SerializeObject(returnJson); } } Our javascript file $(function () { $('#calendar').fullCalendar({ //weekends : false dayClick: function (date) {

Routes for specific controllers

江枫思渺然 提交于 2020-01-05 04:16:09
问题 In my Web API scenario, this (default) route works well for almost all my controllers. config.Routes.MapHttpRoute( name: "DefaultRoute", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); and for a couple of my controllers, I want to have them mapped by their action name, like this: config.Routes.MapHttpRoute( name: "ActionRoute", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); Background: Most of my

WebApi endpoint always gives “404 not found”

时光毁灭记忆、已成空白 提交于 2020-01-05 04:04:28
问题 I am trying to implement WebApi endpoints in a brand new web app but no matter what I try I always get "404 not found" when trying to do a GET from said endpoint. I'm starting simple and just trying to pull a list of vehicles from the database. The directory structure of my application looks like so: The relevant bits of code look like so: dataService.js (function () { var injectParams = ['vehiclesService']; var dataService = function (vehiclesService) { return vehiclesService; }; dataService

WebAPI delete list by HttpClient

浪尽此生 提交于 2020-01-04 19:49:43
问题 In my WebApi I want to have method witch accepts ID list as parameter and deletes them all. So this method looks like code below. [HttpDelete] public IHttpActionResult DeleteList([FromBody]IEnumerable<int> templateIds) I also need Unit Test to be written for this using .NET's HttpClient. So my question is: how can I pass array/list of Ids to WebApi using HttpClient DeleteAsync? :) 回答1: As far as I am aware sending a message body in a HTTP DELETE is ignored in Web Api. An alternative is to