0

내가 http://stevescodingblog.co.uk/basic-authentication-with-asp-net-webapi/ 그것은 인증 헤더를하지 않은 요청 well.If 작동
ASP.NET 웹 API 인증 및 검증

를 참조하여 ASP.NET 웹 API와 사용 인증을 사용, 응답 HttpStatusCode은 "무단"입니다.

일부 json 데이터가 잘못된 열이있는 clientside에서 보내면 요청에 Authorization 헤더가 없더라도 HttpStatusCode 응답은 "Internal Server Error"입니다. (ID가 잘못

[BasicAuthentication] 
public HttpResponseMessage Create(Customer customer) 
{ 
    // 
} 
public class Customer{ 
    public int id{set;get;} 
    public string name{set;get;}  
} 

예를 들어, 콘텐츠 형식이 응용 프로그램/JSON 및 요청 본문 { "사람": "ABC", "이름", "ID"}이며, POST 방법/만들기 보내 int가 아니고 string 임), Authorization 헤더가 없습니다. 응답 HttpStatusCode는 "내부 서버 오류"이며 "허가되지 않은"것이 아닙니다.

고객 인스턴스를 생성하는 것이 권한 부여보다 빠를 수도 있습니다. 먼저 승인을 변경하는 것을 알고 있습니까?

답변

0

BasicAuthentication 속성을 ActionFilterAttribute로 만든 경우 AuthorizationFilterAttribute로 변경해보십시오. 그러면 OnActionExecuting이 OnAuthorization으로 변경됩니다. 나는 그것의 나머지 부분의 대부분이 상당히 유사해야한다고 생각한다.

+0

잘 작동합니다. 고맙습니다. – taiji