webapi

MVC WebApi not using AutofacWebApiDependencyResolver

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a mixed MVC 4 app, where some controllers are regular implementations of Controller and some controllers are implementations of ApiController . I'm also using Autofac for DI, but it appears that the WebApi controller "activator" machinery (for lack for a more specific term) is not using the Autofac resolver ( AutofacWebApiDependencyResolver ), which leads to an exception being thrown when I make a request against one of my api controllers. Here's the error: <Error> <Message>An error has occurred.</Message> <ExceptionMessage> Type

How to setup a webapi controller for multipart/form-data

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to figure out how to get this done. I was not getting any useful error messages with my code so I used something else to generate something. I have attached that code after the error message. I have found a tutorial on it but I do not know how to implement it with what I have. This is what i currently have public async Task PostFile() { if (!Request.Content.IsMimeMultipartContent()) throw new Exception(); var provider = new MultipartMemoryStreamProvider(); var result = new { file = new List () }; var item = new File(); item

ASP.NET WebAPI: How to control string content returned to client?

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: In WebAPI, say I return a string wrapped in an HTTP response: return Request . CreateResponse ( HttpStatusCode . BadRequest , "Line1 \r\n Line2" ); When invoking this action from jQuery, the response text is treated before it is returned. So in the xhr, I get something like this: function success ( xhr ) { alert ( xhr . responseText ); // alerts ""Line1 \\r\\n Line2"" } In other words, the string gets wrapped in double quotes, and special characters get escaped so that they appear in the output (actual alert is "Line1 \r\n Line2",

WebAPI No action was found on the controller

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I got an error - No action was found on the controller 'Action' that matches the request. The url is http://localhost:37331/api/action/FindByModule/1 . The routing I used is config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); Controller: public class ActionController : ApiController { private IActionRepository repository = null; [HttpGet] [ActionName("All")] public IEnumerable<JsonAction> All() { return from action in this.repository.Get() select

SignalR authentication with webAPI Bearer Token

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: +i used this solution to implement Token Based Authentication using ASP.NET Web API 2, Owin, and Identity...which worked out excellently well. i used this other solution and this to implement signalR hubs authorization and authentication by passing the bearer token through a connection string, but seems like either the bearer token is not going, or something else is wrong somewhere, which is why am here seeking HELP...these are my codes... QueryStringBearerAuthorizeAttribute: this is the class in charge of verification using ImpAuth.Entities

WebAPI Gzip when returning HttpResponseMessage

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a WebAPI controller that returns an HttpResponseMessage and I want to add gzip compression. This is the server code: using System.Net.Http; using System.Web.Http; using System.Web; using System.IO.Compression; [Route("SomeRoute")] public HttpResponseMessage Post([FromBody] string value) { HttpContext context = HttpContext.Current; context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress); HttpContext.Current.Response.AppendHeader("Content-encoding", "gzip"); HttpContext.Current.Response.Cache

WebApi: How to handle Images

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am spinning up my 1st WebApi application and I have 2 questions about how to deal with images. 1) What are the different ways to POST/GET images to my service? I think I can either use Base-64 text in JSON or stay native as binary. My understanding is that by converting the image into text, there is a significant increase is package size. 2) If I send the image (from a web form, from a native client, from another service), should I add a Image Controller/Handler or use a Formatter? Is this even an either/or question? I have researched

WebAPI Facebook login returning Access Denied when removing permissions

匿名 (未验证) 提交于 2019-12-03 02:35:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a client app (written with Xamarin) for iOS and WP which uses a WebAPI with Facebook as the sole method of logging in. My issue is that when a user customises the required permissions and removes some of them, the WebAPI simply receives "access_denied" from either OWIN or Facebook (externally to my code). The app is also added to their Facebook account with the subset of restricted permissions they chose, which means on every subsequent login they also get "access denied". Also, because they did not successfully register with the

Dynamically Ignore WebAPI method on controller for api explorer documentation

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: we have implemented a webAPI and we have a number of API controllers. We provide an API documentation for our API and what we want to do is to exclude certain web methods from the documentation but we want this to be done dynamically depending on the environment we are running. just to give you an understanding of what I mean, let's say I have the following web method [ApiExplorerSettings(IgnoreApi = true)] public Product getProduct() { ... } By setting the IgnoreAPI property on the ApiExplorerSettingAttribute to true, it excludes the web

Unauthorised webapi call returning login page rather than 401

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I configure my mvc/webapi project so that a webapi method called from a razor view doesn't return the loginpage when its unauthorised? Its a MVC5 application which also has WebApi controllers for calls via javascript. The two methods below [Route("api/home/LatestProblems")] [HttpGet()] public List<vmLatestProblems> LatestProblems() { // Something here } [Route("api/home/myLatestProblems")] [HttpGet()] [Authorize(Roles = "Member")] public List<vmLatestProblems> mylatestproblems() { // Something there } are called via the following