这个问题一直困扰着我。我正在为我的网络上的用户创建一个自定义授权。我正在使用Windows身份验证。我正试图遵循我在MSDN上找到的一个关于如何做到这一点的例子。唯一的问题是AuthorizationResult给我的类型或命名空间找不到错误。我已经尝试使用System.ComponentModel.DataAnnotations不清除错误。我需要什么参考资料?我的控制器也找不到我的customAuthorization类?
这是我的CustomAuthorization的方法类这是AuthorizationResult抛出错误的地方
protected override AuthorizationResult IsAuthorized(System.Security.Principal.IPrincipal principal, AuthorizationContext authorizationContext)
{
if(authorizationContext.HttpContext.User.IsInRole("hello"))
{
return true;
}
return base.AuthorizeCore(authorizationContext.HttpContext);
}
这是对控制器的调用
[AuthorizeRoleAttribute]//does not find my class
public class HomeController : Controller
{
customAttribute的类定义
public class AuthorizeRoleAttribute : AuthorizeAttribute
{
AuthorizationResult驻留在System.ServiceModel.DomainServices.Server.dll确保您已经引用了此程序集。它不拾取自定义属性类的原因是它无法编译,因为它缺少程序集…