Note that there are some explanatory texts on larger screens.

plurals
  1. POOverride ActionFilter attribute is no working in ASP.NET Web APi 2
    primarykey
    data
    text
    <p>I'm using ASP.NET WEB API 2 to migrate an existing web service.</p> <p>Below is set of filter that I use</p> <pre><code>public class ValidateSession : ActionFilterAttribute { public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) { //var requestMessage = actionContext.Request.Content.ToString(); if (!actionContext.Request.Headers.Contains("source")) { actionContext.Request.Headers.Add("source", "1"); } if (!actionContext.Request.Headers.Contains("appstore_session_id")) { actionContext.Response = actionContext.Request.CreateErrorResponse(System.Net.HttpStatusCode.BadRequest, "Session id is not included in the header"); } } } </code></pre> <p>Below is the code for override the previous ActionFilter attribute</p> <pre><code>public class OverrideSessionValidation : ActionFilterAttribute, IOverrideFilter { public Type FiltersToOverride { get { return typeof(ValidateSession); } } public bool AllowMultiple { get { return true; } } } </code></pre> <p>The code for controller is also give below</p> <pre><code>[ValidateSession] public class SampleController : ApiController { public string GetSessionValues() { return "from session vals"; } [OverrideSessionValidation] public string GetDefaultVals() { return "from DefVals"; } } </code></pre> <p>It can be seen that I have placed the validate session at the class level and for one method I want to override the same. Hence for the second method I used overrideSessionValidation. Though the </p> <p>FiltersToOverride of OverrideSessionValidation is called, I see that onActionExcuting for ValidateSession is also called. I expect that the class filter onActionExecuting should not be called as I have Override for the same.</p> <p>Please let me know what is the error so that I can solve this problem</p> <p>Thanks and regards Venkatesh</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload