我有以下类来实现自定义授权系统:-
[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)) {
filterContext.Result = new HttpUnauthorizedResult("You cannot access this page");
}
base.OnActionExecuting(filterContext);
}
}
但目前当使用 Firefox 访问我的 Web 应用程序时,如果 filterContext.Result = new HttpUnauthorizedResult("You cannot access this page");
返回,用户将不断收到提示窗口以永久输入用户名和密码。那么有没有办法修改我的操作方法,而不是返回 filterContext.Result = new HttpUnauthorizedResult("You cannot access this page");
,而是返回显示消息的视图,例如“您无权执行此操作..”。谢谢