asp.net-web-api

Web api passing array of integers to action method

こ雲淡風輕ζ 提交于 2020-01-21 09:59:06
问题 I have this web api method: [HttpGet] [Route("WorkPlanList/{clientsId}/{date:datetime}")] public async Task<IHttpActionResult> WorkPlanList([FromUri]List<int> clientsId, [FromUri]DateTime date) { } Here is URI that I use to call the action method above: http://localhost/blabla/api/workPlan/WorkPlanList/5,4/2016-06-01 I set the break point on curved bracket and see date time value is passed perfect while clientsId value is 0 . Any idea why I get 0 on clientsId ? 回答1: Your problem intrigued me

Not able to connect to website URLs from Asp.Net WebApi Action Methods

帅比萌擦擦* 提交于 2020-01-21 09:10:09
问题 I am trying to connect to URL using WebClient inside Asp.Net Web Api project. My intention was to get the content and create a web site thumbnail. Sample Code: using (var client = new WebClient()) { var contents = client.DownloadString("http://www.google.com"); } But this WebClient client object throws timeout exception in case of WebApi and same works fine for console application. Kindly help. 回答1: I found the answer here in the end: Web Request through Proxy using RestSharp Adding: <system

disable default validation in Asp.Net WebAPI

好久不见. 提交于 2020-01-21 08:14:10
问题 I want to completely disable model validation for WebAPI controllers. I tried a few ways to do it for MVC, but seems WebAPI doesn't get that methods. In my case: custom formatter creates and populates object default validation happens Object passed to controller My code start working I'm trying to completely remove step 2. 回答1: Try this: config.Services.Clear(typeof(ModelValidatorProvider)); It should completely disable validation both for URI parameters and for body parameters. 来源: https:/

disable default validation in Asp.Net WebAPI

限于喜欢 提交于 2020-01-21 08:13:29
问题 I want to completely disable model validation for WebAPI controllers. I tried a few ways to do it for MVC, but seems WebAPI doesn't get that methods. In my case: custom formatter creates and populates object default validation happens Object passed to controller My code start working I'm trying to completely remove step 2. 回答1: Try this: config.Services.Clear(typeof(ModelValidatorProvider)); It should completely disable validation both for URI parameters and for body parameters. 来源: https:/

disable default validation in Asp.Net WebAPI

僤鯓⒐⒋嵵緔 提交于 2020-01-21 08:12:14
问题 I want to completely disable model validation for WebAPI controllers. I tried a few ways to do it for MVC, but seems WebAPI doesn't get that methods. In my case: custom formatter creates and populates object default validation happens Object passed to controller My code start working I'm trying to completely remove step 2. 回答1: Try this: config.Services.Clear(typeof(ModelValidatorProvider)); It should completely disable validation both for URI parameters and for body parameters. 来源: https:/

How to create a file to populate HttpContext.Current.Request.Files?

痴心易碎 提交于 2020-01-21 07:25:01
问题 In my Web API, The POST action method uploads a file on server. For unit testing this method, I need to create a HttpContext and put a file inside its request: HttpContext.Current.Request.Files So far I am faking HttpContext with this Code which works perfectly: HttpRequest request = new HttpRequest("", "http://localhost/", ""); HttpResponse response = new HttpResponse(new StringWriter()); HttpContext.Current = new HttpContext(request, response); Note that I DON'T want to use Moq or any other

How to create a file to populate HttpContext.Current.Request.Files?

一个人想着一个人 提交于 2020-01-21 07:24:41
问题 In my Web API, The POST action method uploads a file on server. For unit testing this method, I need to create a HttpContext and put a file inside its request: HttpContext.Current.Request.Files So far I am faking HttpContext with this Code which works perfectly: HttpRequest request = new HttpRequest("", "http://localhost/", ""); HttpResponse response = new HttpResponse(new StringWriter()); HttpContext.Current = new HttpContext(request, response); Note that I DON'T want to use Moq or any other

How to restrict DOS attack with Web API

不问归期 提交于 2020-01-21 06:59:27
问题 I am planning to develop a internet site using MVC4 and Web APi. Its a simple application which will display a customer information based on search. For Search functionality I am calling webApi using Ajax get method (I know i should be using Post, but consider this is the current implementation). My Api call is " /api/Data/getSearchResults/?companyName='" + companyName I feel this piece of line can be used as a DOS attack to bring down my server. Is there way i can use Microsoft Anti-XSS

Json response gets truncated in web api using asp.net core

≡放荡痞女 提交于 2020-01-21 06:20:07
问题 I have a web api that returns a json object for me to use on my website. the problem is this: [ { "installment": 1, "date": "03\/01\/2016", "amount": "27.28", "status": "\"01BI000657\"" }, { "installment": 2, "date": "04\/01\/2016", "amount": "49.25", "status": "\"01BI000699\"" }, { "installment": 3, "date": "05\/01\/2016", "amount": "56.31", "status": "\"01BI000745\"" }, { "installment": 4, "date": "06\/01\/2016", "amount": "53.43", "status": "\"01BI000811\"" }, { "installment": 5, "date":

Upload a file MVC 4 Web API .NET 4

£可爱£侵袭症+ 提交于 2020-01-21 03:14:10
问题 I'm using the version of MVC that shipped with Visual Studio 2012 express. (Microsoft.AspNet.Mvc.4.0.20710.0) I assume this is RTM version. I've found plenty of examples online which all use this code: public Task<HttpResponseMessage> PostFormData() { // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } string root = HttpContext.Current.Server.MapPath("~/App_Data"); var