I have to give access rigths to the users of a website. I am doing the filtering here:
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
}
The problem is that I cannot distinguish full View request such as 'Index' from PartialViewRequests or AJAX calls requests.
Therefore the page 'Index'
has access but the 'PartialViewGridViewForIndex'
does not have access.
The property ControllerContext.IsChildAction
does not help either.
You can extend HttpRequestExtensions in asp.net Core 2 as below
And use it as
I would create an Authorization filter by extending the
AuthorizeAttribute
. I would then put my code in theOnAuthorize
override. In theFilterContext
object you can look atFilterContext.ActionDescriptor.MethodInfo.ReturnType.Name
. For a partial view this will bePartialViewResult
.You could use the IsAjaxRequest extension method to determine if an AJAX request was used to invoke this controller action: