asp.net-web-api

Send and receive large file over streams in ASP.NET Web Api C#

孤街浪徒 提交于 2019-12-29 03:29:16
问题 I'm working on a project where I need to send large audio files via streams from a client to a server. I'm using the ASP.NET Web Api to communicate between client and server. My client has a "SendFile" method which I believe works fine, but I don't know how to make my server receive the data I'm sending via a stream. My client code looks like this so far: private const int MAX_CHUNK_SIZE = (1024 * 5000); private HttpWebRequest webRequest = null; private FileStream fileReader = null; private

Return custom error objects in Web API

五迷三道 提交于 2019-12-29 02:43:27
问题 I have a web API I'm working on using the MVC 4 Web API framework. If there is an exception, I'm currently throwing a new HttpResponseException. ie: if (!Int32.TryParse(id, out userId)) throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid id")); This returns an object to the client that is simply {"message":"Invalid id"} I would like to gain further control over this response to exceptions by returning a more detailed object. Something like { "status

Web API Form Data Collection

≡放荡痞女 提交于 2019-12-28 20:33:31
问题 I'm trying to post form serialized values to controller (Web API Self Host). I cannot understand why the NameValueCollection is not correctly bound. Client-side using jQuery: // Form Submit Handler $( '#form-parameters' ).submit(function (event) { event.preventDefault(); var formData = $(this).serialize(); // Post serialized form data postAssemblyParameters(formData); }); // Post Form Data to controller test function postAssemblyParameters(formData){ $.ajax({ url: http://localhost/api/test/1,

Setting IgnoreSerializableAttribute Globally in Json.net

人盡茶涼 提交于 2019-12-28 14:41:08
问题 I'm working on a ASP.NET WebApi (Release Candidate) project where I'm consuming several DTOs that are marked with the [Serializable] attribute. These DTOs are outside of my control so I'm not able to modify them in any way. When I return any of these from a get method the resulting JSON contains a bunch of k__BackingFields like this: <Name>k__BackingField=Bobby <DateCreated>k__BackingField=2012-06-19T12:35:18.6762652-05:00 Based on the searching I've done this seems like a problem with JSON

Application_Error in global.asax not catching errors in WebAPI

家住魔仙堡 提交于 2019-12-28 12:46:55
问题 For a project I am working on, one of the things we're implementing is something that we have code for in some of my teams older ASP.NET and MVC projects - an Application_Error exception catcher that dispatches an email to the development team with the exception experience and most relevant details. Here's how it looks: Global.asax: protected void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); string path = "N/A"; if (sender is HttpApplication) path = (

How do I create a custom model binder using the `BindModel(HttpActionContext actionContext…` signature?

£可爱£侵袭症+ 提交于 2019-12-28 11:53:26
问题 I need to know how to create a custom IModelBinder in MVC 4 and it has been changed. The new method that has to be implemented is : bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext); 回答1: There are 2 IModelBinder interfaces: System.Web.Mvc.IModelBinder which is the same as in previous versions and hasn't changed System.Web.Http.ModelBinding.IModelBinder which is used by the Web API and the ApiController. So basically inside this method you must set the

Enabling CORS with WebAPI PUT / POST requests?

南笙酒味 提交于 2019-12-28 11:48:06
问题 I've tried following this post but I'm still not quite there: CORS support for PUT and DELETE with ASP.NET Web API In my web.config I have the following: <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <httpProtocol> <customHeaders> <!-- TODO: don't let anyone make requests - only approved clients --> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="Content-Type" /> <add name="Access-Control-Allow-Methods" value

ASP.NET Web Api: The requested resource does not support http method 'GET'

北城余情 提交于 2019-12-28 09:32:39
问题 I've got the following action on an ApiController: public string Something() { return "value"; } And I've configured my routes as follows: routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); In the beta, this worked just fine, but I just updated to the latest Release Candidate and now I'm seeing errors on calls like this: The requested resource does not support http method 'GET'. Why doesn't this work

Can't find Request.GetOwinContext

喜夏-厌秋 提交于 2019-12-28 09:32:07
问题 I have been searching for an hour trying to figure out why this isn't working. I have a ASP.Net MVC 5 application with a WebAPI. I am trying to get Request.GetOwinContext().Authentication, however I can't seem to find how to include GetOwinContext. Here is my code: using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web; using System.Web.Mvc; using System.Web.Security; using TaskPro.Models; namespace TaskPro.Controllers.api

How do I register a controller that has been created in an AREA

守給你的承諾、 提交于 2019-12-28 07:05:48
问题 I am using MVC4's WEB API to expose a controller. Initially I created created a MVC4 WEBAPI project, set the project not to open any web page, wait for an external app to call the URL (WEB API). The project in VS2010 is set to run from IIS7 Express, not VS2010's Dev Server. This works OK, the browser prompts me to down load a file. Which is OK for me, as the browser does not know what to do with the returned data (RAW TEXT). Next, I created an AREA in the MVC4 project area, then added a