public class CustomAuthorizeAttribute : AuthorizationFilterAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
return true;// if my current user is authorised
}
}
위는 내 CustomAuthorizeAttribute 클래스이며
[CustomAuthorize] // both [CustomAuthorize] and [CustomAuthorizeAttribute ] I tried
public class ProfileController : ApiController
{
//My Code..
}
내가 전화 할 때
http://localhost:1142/api/Profile
발사되지 않습니다 CustomAuthorizeAttribute
My FilterConfig 클래스에 대한 자세한 내용은 다음과 같습니다.
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new CustomAuthorizeAttribute());
}
}
내가 뭔가를 놓친 경우 도와주세요.
HttpContextBase
. 대신 System.Web.Http.Filters
네임 스페이스 의 필터를 사용하십시오 .웹 API 필터 코드 : https://github.com/aspnetwebstack/aspnetwebstack/blob/master/src/System.Web.Http/Filters/AuthorizationFilterAttribute.cs
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다