我正在尝试构建自定义的AuthorizeAttribute,所以在我的Core项目(一个类库)中,我有这个代码:
using System; using System.Web; using System.Web.Mvc; using IVC.Core.Web; using System.Linq; namespace IVC.Core.Attributes { public class TimeShareAuthorizeAttribute : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContextBase httpContext) { if(!httpContext.Request.IsAuthenticated) return false; var rolesProvider = System.Web.Security.Roles.Providers["TimeShareRoleProvider"]; string[] roles = rolesProvider.GetRolesForUser(httpContext.User.Identity.Name); if(roles.Contains(Website.Roles.RegisteredClient,StringComparer.OrdinalIgnoreCase)) { return true; } return false; } protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { filterContext.Result = new RedirectResult("/TimeShare/Account/logon"); base.HandleUnauthorizedRequest(filterContext); } } }
当我尝试构建的东西我得到这个错误:
错误2’IVC.Core.Attributes.TimeShareAuthorizeAttribute.AuthorizeCore(System.Web.HttpContextBase)’:找不到合适的方法覆盖…
我在这里缺少什么?我已经搜索过,但我可以找到的每个网站只是告诉我做我在这里做的。我正在使用mvc2 btw。