asp.net-web-api

RequestEntityTooLarge response from Web Api when trying to upload a file with HttpClient

给你一囗甜甜゛ 提交于 2019-12-30 11:42:49
问题 I'm trying to create a web service to upload files by Post with Asp.Net Web Api. These are the implementations for Client and Web Api respectively: Client: using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://127.0.0.1:44444/"); using (var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture))) { content.Add(new ByteArrayContent(File.ReadAllBytes(filepath))); content.Headers.ContentType = new MediaTypeHeaderValue(

RequestEntityTooLarge response from Web Api when trying to upload a file with HttpClient

时光毁灭记忆、已成空白 提交于 2019-12-30 11:42:26
问题 I'm trying to create a web service to upload files by Post with Asp.Net Web Api. These are the implementations for Client and Web Api respectively: Client: using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://127.0.0.1:44444/"); using (var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture))) { content.Add(new ByteArrayContent(File.ReadAllBytes(filepath))); content.Headers.ContentType = new MediaTypeHeaderValue(

Windows.Web.Http.HttpClient + WEB API Windows Authentication

只愿长相守 提交于 2019-12-30 10:39:07
问题 Im using Windows.Web.Http.HttpClient to connect to my WEB API. Application haven't prompted for userid and password, but recently i changed WEB API by moving AuthorizeAttribute filter from Action to Class level. Now my Windows store 8.1 application prompt for user id and password. Please let me know how to set HttpClient to not prompt the login and password. Can any1 suggest me do i need to add header to my httpcleint using (Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http

Asp.Net Web API Routing not hitting custom action

谁都会走 提交于 2019-12-30 10:37:38
问题 Here is my code: public class SecurityController : ApiController { //GET api/Security/Current public HttpResponseMessage GetCurrent(){ } //POST api/Security/Login public HttpResponseMessage PostLogin(LoginModel model){ } } public class OrdersController : ApiController { [ActionName("Default")] //GET api/Orders public HttpResponseMessage Get(){ } [ActionName("Default")] //GET api/Orders/2 public HttpResponseMessage Get(long id){ } [ActionName("Default")] //POST api/Orders/ public

Bad Request (400) when using Web API Token Authentication from Angular JS

痞子三分冷 提交于 2019-12-30 09:37:40
问题 I want to establish Web API Token Authentication with Angular JS as client. I am very new to this concept of Token Authentication inside Web API. I do not want to use ASP.NET Identity default tables to add or authenticate user. I have my own database and a table called "EmployeeAccess" table which contains EmployeeNumber as User Id and Password. I want to authenticate the users against the values in this table and then want to grant token so that they gets authorized for subsequent call. I

REST webapi URI GET with string instead of id not routing as expected

爱⌒轻易说出口 提交于 2019-12-30 09:37:21
问题 I have the following example where the request is http://{domain}/api/foo/{username} but I get a 404 status code back. No other Get actions exist on this controller. Shouldn't this work? public class FooController : ApiController { public Foo Get(string username) { return _service.Get<Foo>(username); } } 回答1: By default your route will look something like this: config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional

Using Directory.Delete() and Directory.CreateDirectory() to overwrite a folder

纵饮孤独 提交于 2019-12-30 08:13:16
问题 In my WebApi action method, I want to create/over-write a folder using this code: string myDir = "..."; if(Directory.Exists(myDir)) { Directory.Delete(myDir, true); } Directory.CreateDirectory(myDir); // 1 - Check the dir Debug.WriteLine("Double check if the Dir is created: " + Directory.Exists(myDir)); // Some other stuff here... // 2 - Check the dir again Debug.WriteLine("Check again if the Dir still exists: " + Directory.Exists(myDir)); Issue Strangely, sometimes right after creating the

Passing JSON Array from Javascript to Web API Controller method

[亡魂溺海] 提交于 2019-12-30 08:13:03
问题 I was not able to get the JSON array parameters in web api controller method (SaveDetails). Here are my code. JavaScript Code: $.ajax( { url : "api/Test/SaveDetails", type : "POST", data : { "employees": [ { "firstName": "John", "lastName": "Doe" }, { "firstName": "Anna", "lastName": "Smith" }, { "firstName": "Peter", "lastName": "Jones" } ] }, success: function (data) {alert("success");}, error: function () {alert("Error");} }) Controller method [HttpPost] public DataSet SaveDetails(Models

Null reference in web api call

China☆狼群 提交于 2019-12-30 06:59:09
问题 This is a weird one, and I'm at a loss to understand what's going on here. I have a web api project that in one controller a call to a certain method eventually calls a function in a service that looks like this: public MyClassBase GetThing(Guid id) { if (cache.ContainsKey(id)) { return cache[id]; } else { var type = typeof(MyClassBase).Assembly.GetTypes().FirstOrDefault ( t => t.IsClass && t.Namespace == typeof(MyClassBase).Namespace + ".Foo" && t.IsSubclassOf(typeof(MyClassBase)) && (t

ASP.Net Web Api - ApiExplorer does not contain any ApiDescriptions

风格不统一 提交于 2019-12-30 05:57:15
问题 I am trying to implement an Options method in a controller of my web service that will return a message containing the valid HTTP methods for the URI endpoint associated with the controller. My Options method looks something like this: public HttpResponseMessage Options() { var resp = new HttpResponseMessage(); resp.Content = new StringContent(""); var apiExplorer = GlobalConfiguration.Configuration.Services .GetApiExplorer(); foreach (ApiDescription api in apiExplorer.ApiDescriptions) { resp