Design if the controller is in the zone

Is there a way to check if the controller calling the method is called from the controller that is inside the scope?

For example, I have a class that inherits from AuthorizeAttribute, for example.

public class CustomAuthorize: System.Web.Mvc.AuthorizeAttribute
{
    public CustomAuthorize()
    {            
        ...
    }

    protected override bool AuthorizeCore(HttpContextBase httpContext)        
    {                        
        // TODO - Check if the controller is from an Area
    }
}

Then I have some controller actions that are decorated with the corresponding Roles (as well as several other custom attributes), for example.

[CustomAuthorize(Roles ="Administrator")]
[HttpGet]
public virtual ActionResult Index()
{            
  ...
}

In the TODO section above, I would like to find out if the controller is one of the controllers in one of my areas. I know that my controllers in the area will be in the ProjectName.Areas.xxx.Controllers namespace (where xxx is the Area name), while those that are not will be in the ProjectName.Controllers namespace.

- (, ?), AuthorizeCore , ( , ), ?

+4
2

RouteData.DataTokens:

httpContext.Request.RequestContext.RouteData.DataTokens["area"]

null, , .

+2

MCV Area, Google. , .

ASP.NET MVC -

0

Source: https://habr.com/ru/post/1667882/


All Articles