asp.net-web-api

OWIN/OAuth2 3rd party login: Authentication from Client App, Authorization from Web API

牧云@^-^@ 提交于 2020-01-20 21:46:21
问题 I am trying to create a Web API that allows the API's clients (native mobile apps) to login using a 3rd party cloud storage provider. I'm using the following general flow from Microsoft: Here is what I am trying to achieve: I am using the default ASP.NET Web API Visual Studio template with external authentication, along with the OWin.Security.Providers Nuget package for Dropbox login functionality, and the existing built-in login functionality for Google (Drive) and Microsoft (OneDrive). The

OWIN/OAuth2 3rd party login: Authentication from Client App, Authorization from Web API

你。 提交于 2020-01-20 21:46:11
问题 I am trying to create a Web API that allows the API's clients (native mobile apps) to login using a 3rd party cloud storage provider. I'm using the following general flow from Microsoft: Here is what I am trying to achieve: I am using the default ASP.NET Web API Visual Studio template with external authentication, along with the OWin.Security.Providers Nuget package for Dropbox login functionality, and the existing built-in login functionality for Google (Drive) and Microsoft (OneDrive). The

How does one correctly implement a MediaTypeFormatter to handle requests of type 'multipart/mixed'?

╄→尐↘猪︶ㄣ 提交于 2020-01-20 14:25:06
问题 Consider a web service written in ASP.NET Web API to accept any number files as a 'multipart/mixed' request. The helper method mat look as follows (assuming _client is an instance of System.Net.Http.HttpClient ): public T Post<T>(string requestUri, T value, params Stream[] streams) { var requestMessage = new HttpRequestMessage(); var objectContent = requestMessage.CreateContent( value, MediaTypeHeaderValue.Parse("application/json"), new MediaTypeFormatter[] {new JsonMediaTypeFormatter()}, new

How does one correctly implement a MediaTypeFormatter to handle requests of type 'multipart/mixed'?

折月煮酒 提交于 2020-01-20 14:22:51
问题 Consider a web service written in ASP.NET Web API to accept any number files as a 'multipart/mixed' request. The helper method mat look as follows (assuming _client is an instance of System.Net.Http.HttpClient ): public T Post<T>(string requestUri, T value, params Stream[] streams) { var requestMessage = new HttpRequestMessage(); var objectContent = requestMessage.CreateContent( value, MediaTypeHeaderValue.Parse("application/json"), new MediaTypeFormatter[] {new JsonMediaTypeFormatter()}, new

Web API OData Inlinecount not working

a 夏天 提交于 2020-01-19 04:48:05
问题 I am using the out of the box ValuesController in a ASP.NET Web API application public class ValuesController : ApiController { // GET api/values [Queryable(PageSize = 1)] public IQueryable<string> Get() { return new string[] { "value1", "value2", "value3", "value4", "value5" }.AsQueryable(); } } When I get http://localhost/api/values?$inlinecount=allpages This is the response <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

Web API OData Inlinecount not working

一笑奈何 提交于 2020-01-19 04:48:05
问题 I am using the out of the box ValuesController in a ASP.NET Web API application public class ValuesController : ApiController { // GET api/values [Queryable(PageSize = 1)] public IQueryable<string> Get() { return new string[] { "value1", "value2", "value3", "value4", "value5" }.AsQueryable(); } } When I get http://localhost/api/values?$inlinecount=allpages This is the response <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

HttpContext.Current is null when unit test

大兔子大兔子 提交于 2020-01-19 01:48:48
问题 I have following web Api controller method. When I run this code through web, HttpContext.Current is never null and give desired value. public override void Post([FromBody]TestDTO model) { var request = HttpContext.Current.Request; var testName = request.Headers.GetValues("OS Type")[0]; // more code } However, when I call this method from Unit Test , HttpContext.Current is always null. How do i fix it? 回答1: During unit tests HttpContext is always null as it is usually populate by IIS. You

How to consume a webApi from asp.net? [duplicate]

谁都会走 提交于 2020-01-17 17:29:10
问题 This question already has answers here : ASP.NET MVC 4 Application Calling Remote WebAPI (5 answers) Closed 5 years ago . I need to do project which call api's from database and make another project and call the old one which contain api's only in its controller I face those problems 1- I want to return an object from api which takes object and return object as this is my api which locate in "testController" [HttpPost] [ActionName("fetch_information")] public login_info fetch_information

C# WebApi + Angular 4 Set-Cookie doesn't save cookies

两盒软妹~` 提交于 2020-01-17 09:31:14
问题 I'm doing an http request to my API that is supposed to send me back two cookies with the Set-Cookie Header. It seems that the cookie is correctly send back for this Init Request but they are not saved in Chrome, so for later requests the cookies are not sent. My Init response headers are : Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:content-type Access-Control-Allow-Origin:http://localhost:4200 Cache-Control:no-cache Content-Length:0 Date:Thu, 20 Apr 2017 09:25:45 GMT

Set JsonSerializerSettings Per Response?

旧街凉风 提交于 2020-01-17 08:26:51
问题 I have an MVC 4 Web API. Usually I want responses to return all properties, but there is one place I only want to return only non-null values. I can setup either behavior by setting the JsonSerializerSettings of the Formatters.JsonFormatter.SerializerSettings.NullValueHandling of the GlobalConfiguration.Configuration instance in the global file but I want to use both depending on the response. Is there an easy way to configure the request scope from within an API controller action? 回答1: By