I have the following action filter class:-
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class CheckUserPermissionsAttribute : ActionFilterAttribute
{
Repository repository = new Repository();
public string Model { get; set; }
public string Action { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
string ADusername = filterContext.HttpContext.User.Identity.Name.Substring(filterContext.HttpContext.User.Identity.Name.IndexOf("\\") + 1);
if (!repository.can(ADusername,Model,Action)) {
var viewResult = new ViewResult();
viewResult.ViewName = "~/Views/Errors/Unauthorized.cshtml";
filterContext.Result = viewResult;}
base.OnActionExecuting(filterContext);
}}
But I need to return two views based on the request type, if it is Ajax or not such as:-
If (Request.IsAjaxRequest()){
viewResult.ViewName = "~/Views/Errors/_PartialUnauthorized.cshtml";
}
else{
viewResult.ViewName = "~/Views/Errors/Unauthorized.cshtml";
but I can not reference Request inside the class ? can anyone advice please ?