asp.net-web-api2

Creating new IHttpActionResult action result methods

白昼怎懂夜的黑 提交于 2019-12-20 09:47:55
问题 Is there a way I can use the new IHttpActionResult interface to return a HttpStatusCode.NoContent response message? I am currently using return new HttpResponseMessage( HttpStatusCode.NoContent ); and would like to convert this into return NoContent(); . IHttpActionResult has already got Ok() , Conflict() and NotFound() but I cannot find any for Forbidden() and NoContent() which I need to use in my project. How easy is it to add other result types? 回答1: There's no convenience method for no

Web API 2 : Best Practice returning ViewModel data from Controller to $http Success result ?

回眸只為那壹抹淺笑 提交于 2019-12-20 07:56:21
问题 I wonder what's the recommended way to handle data (ViewModels) in Web Api 2.. I have googled around quite much, and found some "recepies" but i wonder what's the most flexible and easy way of handling this.. This call returns error --> GET http://localhost:63203/api/Gallery/GetPhotosForPage 404 (Not Found) probably because of some signature error..,. Here is the $http call (Angular) : var currPage = $location.path() || "Unknown"; $http({ method: 'GET', url: '/api/Gallery/GetPhotosForPage',

get 404 when trying to access files directly [duplicate]

人走茶凉 提交于 2019-12-20 06:31:31
问题 This question already has answers here : HTML page with images using .net WebApi (2 answers) Closed last year . I have a WebApi project with a folder called "images". I want to access the images directly but I keep getting 404 with message "No type was found that matches the controller named 'images'." I did the same thing on MVC project and it always worked well, I don't know why in WebApi I can't access files. I'm sure the file is there, I see it in the directory. Example request: GET http:

get 404 when trying to access files directly [duplicate]

回眸只為那壹抹淺笑 提交于 2019-12-20 06:30:30
问题 This question already has answers here : HTML page with images using .net WebApi (2 answers) Closed last year . I have a WebApi project with a folder called "images". I want to access the images directly but I keep getting 404 with message "No type was found that matches the controller named 'images'." I did the same thing on MVC project and it always worked well, I don't know why in WebApi I can't access files. I'm sure the file is there, I see it in the directory. Example request: GET http:

Unable to inject DBContext into my Web API 2 Controller with Unity

浪尽此生 提交于 2019-12-20 04:25:16
问题 I've been at it for days, but I can't get Unity to inject anything with RegisterType<> into my Controller . I'm using Web Api 2, in Visual Studio 2015, with Unity 4. Whenever I try to inject IUnitOfWork or IRFContext , I get "message": "An error occurred when trying to create a controller of type 'ClPlayersController'. Make sure that the controller has a parameterless public constructor." . I'm using the Unity.AspNet.WebApi to bootstrapp into WebApi. Below is my UnityWebApiActivator [assembly

Controller Versioning in Web Api 2 using URL

北城余情 提交于 2019-12-20 04:05:36
问题 I want to use URL-Based versioning for my controller. best solution that I found was code below. I'm looking for better solution for this. I tried Constrain It didn't work maybe i did some thing wrong my only concern is using controller with same name in different namespace...?! I userd string merging to creating wanted type. probably it is not a good idea. Please send good reference for this topic if you know any.....? public class ControllerVersioning : DefaultHttpControllerSelector {

Controller Versioning in Web Api 2 using URL

雨燕双飞 提交于 2019-12-20 04:05:21
问题 I want to use URL-Based versioning for my controller. best solution that I found was code below. I'm looking for better solution for this. I tried Constrain It didn't work maybe i did some thing wrong my only concern is using controller with same name in different namespace...?! I userd string merging to creating wanted type. probably it is not a good idea. Please send good reference for this topic if you know any.....? public class ControllerVersioning : DefaultHttpControllerSelector {

WEB API 2 Delete returns 405

試著忘記壹切 提交于 2019-12-20 03:09:22
问题 I'm trying to do create a delete function in my web API class. I had problems earlier with using the Put and Patch Http messages since these were being linked to WebDAV. After changing this the Patch and Put worked but the Delete is giving me issues. Here is my class: [RoutePrefix("api/Account")] public class AccountController : ApiController { //private AuthRepository _repo = null; Orchestrate.Net.Orchestrate orchestrate = new Orchestrate.Net.Orchestrate("0b42c04c-0d70-4da8-a3c1-2036882369d0

Can user authorization be set on a per-controller basis in web.config? (cannot use AuthorizeAttribute)

限于喜欢 提交于 2019-12-20 02:54:18
问题 I have a Web API 2 app using windows auth. I have multiple controllers and this in my web.config for authorization: <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> <authentication mode="Windows" /> <authorization> <allow users="AllowedUsersAndGroups" /> <deny users="?" /> </authorization> <sessionState mode="Off" /> </system.web> This "blanket" authorization works great, but I have 2 specific controllers that I need to lock down

Controller without the controller suffix

牧云@^-^@ 提交于 2019-12-20 02:38:07
问题 based on my design requirements, I will like to exclude the suffix 'Controller' from my controllers and replace it with 'Resource'. So that 'FundsController' will become 'FundsResource'. The problem is that I am not able to route to my specified actions by either convention based or attribute routing when I change replace the term 'Controller' and get an error saying that the controller with this name could not be found. How can I satisfy the above mentioned design requirement and also be