asp.net-web-api2

Getting an access token in ASP.NET 5

早过忘川 提交于 2019-11-26 17:07:28
问题 My ASP.NET 5 (MVC 6 + beta7) web application (MVC + WebAPI) is required to get back an access_token from WebAPI login calls. So far, from googling, I have created the following code for startup.cs: app.UseOAuthBearerAuthentication(options => { options.AutomaticAuthentication = true; options.Audience = "http://localhost:62100/"; options.Authority = "http://localhost:62100/"; }); My client side is: var login = function () { var url = "http://localhost:62100/"; var data = $("#userData")

Web API 2, OWIN Authentication, SignOut doesn't logout

十年热恋 提交于 2019-11-26 15:58:56
问题 I'm doing some research for work with a view to using Bearer tokens as an authentication mechanism (i.e. AngularJS UI, authenticates via OWIN in a Web API [2] project). I have the login working fine, role information and all that is fine, but I cannot get the token to logout. My startup configuration is this: OAuthOptions = new OAuthAuthorizationServerOptions() { TokenEndpointPath = new PathString("/Token"), Provider = new ApplicationOAuthProvider(PublicClientId), AccessTokenExpireTimeSpan =

Web API 2: how to return JSON with camelCased property names, on objects and their sub-objects

江枫思渺然 提交于 2019-11-26 15:55:24
UPDATE Thanks for all the answers. I am on a new project and it looks like I've finally got to the bottom of this: It looks like the following code was in fact to blame: public static HttpResponseMessage GetHttpSuccessResponse(object response, HttpStatusCode code = HttpStatusCode.OK) { return new HttpResponseMessage() { StatusCode = code, Content = response != null ? new JsonContent(response) : null }; } elsewhere... public JsonContent(object obj) { var encoded = JsonConvert.SerializeObject(obj, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling

How to return a PDF from a Web API application

依然范特西╮ 提交于 2019-11-26 15:46:47
问题 I have a Web API project that is running on a server. It is supposed to return PDFs from two different kinds of sources: an actual portable document file (PDF), and a base64 string stored in a database. The trouble I'm having is sending the document back to a client MVC application. The rest of this is the details on everything that's happened and that I've already tried. I have written code that successfully translates those two formats into C# code and then (back) to PDF form. I have

Pass multiple complex objects to a post/put Web API method

南楼画角 提交于 2019-11-26 15:37:30
问题 Can some please help me to know how to pass multiple objects from a C# console app to Web API controller as shown below? using (var httpClient = new System.Net.Http.HttpClient()) { httpClient.BaseAddress = new Uri(ConfigurationManager.AppSettings["Url"]); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = httpClient.PutAsync("api/process/StartProcessiong", objectA, objectB); } My

Registering Web API 2 external logins from multiple API clients with OWIN Identity

不打扰是莪最后的温柔 提交于 2019-11-26 14:59:08
问题 I would like the following architecture (I've made up the product name for this example): Web API 2 application running on one server http://api.prettypictures.com MVC 5 client app running on another server http://www.webpics.com I would like www.webpics.com client app to use the Pretty Pictures API to: Register new accounts with username and password Register new accounts with Facebook/Google/Twitter/Microsoft Log in Retrieve pictures All of the above works except registering external

Web API and OData- Pass Multiple Parameters

╄→гoц情女王★ 提交于 2019-11-26 14:14:55
问题 Is it possible to get OData to do the following? I would like to be able to query a REST call by passing on parameters than may not be the primary key. Can I call a REST method like --> GetReports(22, 2014) or Reports(22, 2014) ? [HttpGet] [ODataRoute("Reports(Id={Id}, Year={Year})")] public IHttpActionResult GetReports([FromODataUri]int Id, [FromODataUri]int Year) { return Ok(_reportsRepository.GetReports(Id, Year)); } Here is my latest change. //Unbound Action OData v3 var action = builder

Post byte array to Web API server using HttpClient

烂漫一生 提交于 2019-11-26 14:12:11
问题 I want to post this data to Web API server: public sealed class SomePostRequest { public int Id { get; set; } public byte[] Content { get; set; } } Using this code for server: [Route("Incoming")] [ValidateModel] public async Task<IHttpActionResult> PostIncomingData(SomePostRequest requestData) { // POST logic here } and this - for client: var client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:25001/"); client.DefaultRequestHeaders.Accept.Clear(); client

JsonConverter with Interface

社会主义新天地 提交于 2019-11-26 09:13:59
问题 I have an object which comes from the client and get deserialized from the Web Api 2 automatically. Now I have a problem with one property of my model. This property \"CurrentField\" is of Type IField and there are 2 different Implementations of this interface. This is my model (just a dummy) public class MyTest { public IField CurrentField {get;set;} } public interface IField{ string Name {get;set;} } public Field1 : IField{ public string Name {get;set;} public int MyValue {get;set;} }

FromBody string parameter is giving null

放肆的年华 提交于 2019-11-26 09:03:56
问题 This is probably something very basic, but I am having trouble figuring out where I am going wrong. I am trying to grab a string from the body of a POST, but \"jsonString\" only shows as null. I also want to avoid using a model, but maybe this isn\'t possible. The piece of code that I am hitting with PostMan is this chunk: [Route(\"Edit/Test\")] [HttpPost] public void Test(int id, [FromBody] string jsonString) { ... } Maybe it is something I am doing incorrectly with postman, but I have been