웹 API를 구현했습니다.WebApi : User.Identity.IsAuthenticated 첫 번째 요청에 대해 true이고 그 이후에 false
<authentication mode="None" />
기본 권한을 사용하고 Thread.CurrentPrincipal을 내 AuthorizeAttribute에 설정합니다.
응용 프로그램을 시작/디버깅 한 후 처음으로 서버 측에서 Thread.CurrentPrincipal (IsAuthenticated = true로 설정) 요청을 제출하고 IsAuthenticated가 내 컨트롤러에서 true를 반환합니다. 그러나이 이후의 모든 요청은 Thread.CurrentPrincipal을 정상적으로 설정하지만 실행이 내 컨트롤러 메서드에 도달하면 컨트롤러의 User.Identity 속성이 변경되고 IsAuthenticated = false가됩니다.
응용 프로그램을 시작한 후 처음으로 IsAuthenticated = true를 왜인지 알 수 없습니까?! Thread.CurrentPrinciple을 수동으로 설정하고있을 때마다 매번 그러해야합니다. 그러나 어딘가에있을 때와 내 컨트롤러를 때리면 대체됩니다!
UPDATE
그것은 내가 추가 한 MediaTypeFormatter 함께 할 수있는 뭔가입니다. 포맷터를 제거하면 문제가 발생하지 않습니다. 실행됩니다 포맷터의 코드는 다음과 같습니다 :
public override Task<object> ReadFromStreamAsync(Type type, System.IO.Stream webStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger)
{
return Task.Factory.StartNew(() =>
{
string temporaryFilePath = Path.Combine(TemporaryDirectory, Path.GetRandomFileName());
using (FileStream fileStream = new FileStream(temporaryFilePath, FileMode.CreateNew, FileAccess.Write, FileShare.Read))
{
webStream.CopyTo(fileStream);
}
return (object)new CustomFile(temporaryFilePath);
});
}