Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Vishal Joshi 5 posts 25 karma points
    Feb 03, 2012 @ 13:26
    Vishal Joshi
    0

    Custom attribute on controller's action in umbraco plugin is not getting called.

    Hello,

    I have a plugin project where I have defined my controller class say TestController and have defined an action say TestAction having ChildActionOnly attribute. I have also decorated this action with my custom attribute say CustomAuthorizationAttribute. When this action method is called, MVC is supposed to call the OnAuthorization or AuthorizeCore method which is not happening. I am not sure what is wrong in the code as this is a standard approach to define the custom attribute for action method or there is any other procedure.

    Below is the class written for custom authorization attribute

        public class CustomAuthorizationAttributeAuthorizeAttribute
        {
            public CustomAuthorizationAttribute() { }
    
            public CustomAuthorizationAttribute(string actionName)
            {
                //Some logic here
            }
    
            protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
            {
                bool someValue = true;
    
                //Set someValue variable as per custom authorization logic here
    
                return someValue;
            }
        }

     

    I have also tried OnAuthorization method but it is also net getting called.

    Below is the action method that uses CustomAuthorizationAttribute

    public class TestController : SurfaceController
        {
            [ChildActionOnly]
            [CustomAuthorization("Index")]
            public PartialViewResult TestAction()
            {
                return PartialView();
            }
        }

     

    However, the code for custom authorization attribute gets called if I mark the action with [HttpPost] attribute only. It seems this is not working for the actions marked with [ChildActionOnly] attribute only.

    I am using Umbraco 5(Jupiter) version which is completely based on MVC architecture and my plugin DLLs are located in umbraco project under below path

    App_Plugins\Packages\Plugin_Name\lib

    If anyone has come across such scenario and got workaround, please provide help.

    Any kind of pointers will be very helpful.

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft