asp.net-apicontroller

Owin WebApi service ignoring ExceptionFilter

点点圈 提交于 2019-12-08 02:15:14
问题 Stack, For some reason my Owin WebApi service is ignoring our custom exception handler. I'm following documentation for asp.net exception handling. Here are the simplified implementation details (scrubbed out business proprietary stuff). Can you someone point out what I'm overlooking? Custom exception filter: public class CustomExceptionFilter : ExceptionFilterAttribute { public override void OnException(HttpActionExecutedContext actionExecutedContext) { actionExecutedContext.Response

APIController “Executed” method?

南笙酒味 提交于 2019-12-07 10:23:16
问题 In an ApiController action I need to close a connection to a database as soon as the action is finished executing. Under a controller I override OnActionExecuted to accomplish this. How would I accomplish this under an ApiController action? Thanks 回答1: You could override the ExecuteAsync method: public override Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken) { return base .ExecuteAsync(controllerContext, cancellationToken)

Owin WebApi service ignoring ExceptionFilter

牧云@^-^@ 提交于 2019-12-06 09:32:28
Stack, For some reason my Owin WebApi service is ignoring our custom exception handler. I'm following documentation for asp.net exception handling . Here are the simplified implementation details (scrubbed out business proprietary stuff). Can you someone point out what I'm overlooking? Custom exception filter: public class CustomExceptionFilter : ExceptionFilterAttribute { public override void OnException(HttpActionExecutedContext actionExecutedContext) { actionExecutedContext.Response.StatusCode = HttpStatusCode.NotFound; actionExecutedContext.Response.Content = new StringContent("...my

ASP.NET MVC 4 ApiController and Normal Controller Routes

心已入冬 提交于 2019-12-04 03:46:16
问题 I have a project that is used solely for API requests into our app and we are using an ASP.NET MVC 4 project. We have some Controllers that derive from the ApiController and others that derive from the normal Controller class. The issue is that I don't want to have the default routing for the ApiControllers of api/XXXXX/ . I want the same routing to be used for the ApiControllers as the non-Api Controllers, namely {controller}/{action}/{id} . I tried adding the following routes routes

ApiController vs ODataController when exposing DTOs

五迷三道 提交于 2019-12-03 05:45:43
问题 Can someone explain me when I should inherit my controller form ODataController vs ApiController ? The question is caused by the fact that results returned by ApiController can be filtered with OData query. If I apply QueraybleAttribute to contoller's methods, query is processed even if action returns IEnumerable . However without this attribute but with the call config.EnableQuerySupport() , query is processed only if method returns IQueryable . I think it is not consistent behavior. WebAPI

ApiController vs ODataController when exposing DTOs

僤鯓⒐⒋嵵緔 提交于 2019-12-02 20:21:46
Can someone explain me when I should inherit my controller form ODataController vs ApiController ? The question is caused by the fact that results returned by ApiController can be filtered with OData query. If I apply QueraybleAttribute to contoller's methods, query is processed even if action returns IEnumerable . However without this attribute but with the call config.EnableQuerySupport() , query is processed only if method returns IQueryable . I think it is not consistent behavior. WebAPI documentation and examples imply that controller must inerit from ODataController. And I'm a little

Azure Web Api - Waiting Sql Connection every 4 minutes and 30 minutes

社会主义新天地 提交于 2019-12-01 16:52:10
问题 Within a request on an ApiController, I'm tracking the duration of awaiting the Sql Connection to open. await t.TrackDependencyAsync(async() => { await sqlConnection.OpenAsync(); return true; }, "WaitingSqlConnection"); If my request is not called for at least 5 minutes, then any new call will see the duration of OpenAsync be huge (c. 3s) instead of immediate. I'd like to understand the reason to eradicate that crazy slowness. UPDATE I created an endpoint just to open the SqlConnection . If I

Passing JSON Array from Javascript to Web API Controller method

隐身守侯 提交于 2019-12-01 03:55:23
I was not able to get the JSON array parameters in web api controller method (SaveDetails). Here are my code. JavaScript Code: $.ajax( { url : "api/Test/SaveDetails", type : "POST", data : { "employees": [ { "firstName": "John", "lastName": "Doe" }, { "firstName": "Anna", "lastName": "Smith" }, { "firstName": "Peter", "lastName": "Jones" } ] }, success: function (data) {alert("success");}, error: function () {alert("Error");} }) Controller method [HttpPost] public DataSet SaveDetails(Models.Person[] obj) { //save opertion. } Model Method: public class Person { public string firstName { get;

Circular references preventing serialization of object graph

天涯浪子 提交于 2019-11-27 21:57:10
I've got a simple data model involving Weeds and Weed Families. WeedFamily <-1---*-> Weed (WeedFamily and Weed have a one-to-many relationship) I'm attempting to complete my first ApiController so that I can easily retrieve my data as JSON for an AngularJS application. When I access the /WeedAPI/ URL in my application, I get the following error. I'm pretty sure the problem is that I have circular references between Weed and WeedFamily . How should I change my data model so that the JSON serialization will work while maintaining the bi-directional quality of the Weed - WeedFamily relationship?

Circular references preventing serialization of object graph

穿精又带淫゛_ 提交于 2019-11-26 20:55:38
问题 I've got a simple data model involving Weeds and Weed Families. WeedFamily <-1---*-> Weed (WeedFamily and Weed have a one-to-many relationship) I'm attempting to complete my first ApiController so that I can easily retrieve my data as JSON for an AngularJS application. When I access the /WeedAPI/ URL in my application, I get the following error. I'm pretty sure the problem is that I have circular references between Weed and WeedFamily . How should I change my data model so that the JSON