asp.net-web-api2

How to prevent HTTP 404 for a custom action in an odata controller?

烈酒焚心 提交于 2019-12-11 06:05:12
问题 I have an ASP.Net WebApi2 project hosting odata both ApiController and ODataController . And I want to add a custom action in an ODataController . I saw this seems to be achievable by either adding [HttpPost] attribute on the desired action, or by configuring the ODataConventionModelBuilder with a specific FunctionConfiguration when using the MapODataServiceRoute. To distinguish between odata routes and webapi routes we use the following scheme : odata : http://localhost:9292/myProject/odata

UnitOfWork, Repository Database Connection Issue

拥有回忆 提交于 2019-12-11 05:35:18
问题 I'm using Unity for Dependency Injection. I implemented generic repository IRepository<T> and IUnitOfWork as per direction mentioned here Now when I access Repository and UnitOfWork in Service layer using constructor injection, it adds the data in database but never closes connection with database. UnitOfWork implements IDisposable but that's never called since I'm not able to implement Using pattern knowing the fact that Repository and UnitOfWork is being shared by other functions also.

How to setup IIS TransferRequestHandler path for both WebApi 2 and OData Controllers?

人盡茶涼 提交于 2019-12-11 05:14:14
问题 I'm looking to properly configure System.Web.Handlers.TransferRequestHandler path attribute to handle both routes to WebApi REST actions and ODataController custom function in an ASP.NET WebApi 2 project. My web.config file handlers are configured as follow in order to support custom ODataController functions call (see my related question here) : <handlers> <clear/> <remove name="ExtensionlessUrlHandler-Integrated-4.0"/> <remove name="OPTIONSVerbHandler"/> <remove name="TRACEVerbHandler"/>

Authenticate using Windows Authentication on single action and not whole application

試著忘記壹切 提交于 2019-12-11 04:59:01
问题 I would like to authenticate using Windows Integrated Authentication on a single controller action instead of the global application. I have read many articles online and StackOverflow, but have not found an answer. Note, I'm developing in Web API 2.0 and not MVC. That said, typically to enable Windows Authentication on your whole application, you'd do something like Web API documentation describes: <system.web> <authentication mode="Windows" /> </system.web> Under the covers, I'm not sure

AngularJS save image file sent from Web API 2

时光总嘲笑我的痴心妄想 提交于 2019-12-11 04:56:50
问题 I have been trying to follow different posts on downloading a file sent from my Web API. So far I can get the file to come, it will open the download window and it will save. However, I cannot open it so something must be wrong somewhere. Here is my AngularJS so far. return $http({ url: State.Endpoint + "/api/account/picture", method: "GET", responseType: 'arrayBuffer' }).then(function (data) { var octetStreamMime = 'application/octet-stream'; var success = false; var file = new Blob([data

Ajax: Response for preflight has invalid HTTP status code 404

给你一囗甜甜゛ 提交于 2019-12-11 04:49:09
问题 I have services and when i call it I get error, Response for preflight has invalid HTTP status code 404 as shown in below picture. please here me to solve this problem Thank you Here is ajax $.ajax({ url:url, type: "Get", async: true, contentType: "application/text", dataType: "json", cache: false, crossDomain: true, success: function (data) { } } }); Web.config <system.webServer> <httpProtocol> <customHeaders> <remove name="X-Powered-By" /> <add name="Access-Control-Allow-Origin" value="*" /

authorization has been denied for this request using JWT

点点圈 提交于 2019-12-11 04:28:00
问题 I am trying to implement JWT authentication using OWIN middleware for my ASP.NET WebAPI 2.0. I am through with the first task of obtaining the jwt token from the OAuthAuthorizationServer. The resource owner and token server are same i.e same WebAPI generates the token and should consume too to provide access to resources. In my Global.asax file I have added the below code line GlobalConfiguration.Configure(FilterConfig.Configure); In my Filter.config I have added the following configure

OWIN Middleware not able to set http status code

≡放荡痞女 提交于 2019-12-11 04:24:20
问题 I am running WebAPI with just one Middleware and not able to set response HTTP status code. I am using OnSendingHeaders() and able to add headers and set response body, but status code is not getting set and response always has it set as 200 OK. I am able to set response status code in ValidateUrl(context) though. Difference is ValidateUrl(context) is called synchronously and OnSendingHeaders() would be called asynchronously after ProcessIncomingRequest() is executed. Is HTTP status line

How to send custom object with modelState, or expand modelState object

跟風遠走 提交于 2019-12-11 03:59:35
问题 This is a follow-up question from How to send a custom object from OnException method? This is my current code for OnActionExecuting : public override void OnActionExecuting(HttpActionContext actionContext) { var modelState = actionContext.ModelState; if (!modelState.IsValid) actionContext.Response = actionContext.Request .CreateErrorResponse(HttpStatusCode.BadRequest, modelState); } All my WebAPI requests use this filter which checks whether the model is valid or not. If not, it will send

error: Make sure that the controller has a parameterless public constructor webapi

萝らか妹 提交于 2019-12-11 03:55:58
问题 I am using webapi, unity, and mvc. I am getting the error "Make sure that the controller has a parameterless public constructor". I have seen treads on similar problems but still can't get it to work. I have installed unity.webapi and seem to have all the necessary references: Microsoft.Practices.Unity - runtime: v4.0.30319, version: 3.5.0.0 Microsoft.Practices.Unity.Mvc - runtime: v4.0.30319, version: 3.5.0.0 Unity.WebApi - runtime: v4.0.30319, version: 5.1.0.0 System.Web.Http - runtime: v4