Я использую Windows Auth, и он отлично работал на этом контроллере odata. Но после того, как я получил последний пакет NuGet (предварительная версия 5.0.0-rc1), что-то изменилось, и ApiController.User
имеет значение NULL. Это больше не пропускает Windows Auth. Есть идеи? Я попытался добавить атрибут [Авторизовать], но это не сработало - возможно, для этого требуется больше настроек в другом месте.odata ApiController.User == NULL после обновления до web api 5.0.0-rc1
public class ProductsController : EntitySetController<Product, int>
{
protected ProjectContextUnitOfWork UoW;
protected UserRepository UserRepo;
protected ProductRepository ProductRepo;
protected Project.Models.User CurrentUser;
// odata/Products/
public ProductsController()
{
if (!User.Identity.IsAuthenticated)
{
HttpResponseMessage msg = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "User not authenticated.");
throw new HttpResponseException(msg);
}
ProjectUserPrincipal LoggedInUser = this.User as ProjectUserPrincipal;
// - closed in Dispose()
UoW = new ProjectContextUnitOfWork(false); //without lazy loading
UserRepo = new UserRepository(UoW);
ProductRepo = new ProductRepository(UoW);
CurrentUser = UserRepo.Get(LoggedInUser.Username, LoggedInUser.Domain);
}
protected override Product GetEntityByKey(int id)
{
var x = from b in ProductRepo.GetAvailableProductsWithNumbers(CurrentUser)
where b.Id == id
select b;
return x.FirstOrDefault();
}
...
}
Другие детали:
- .NET 4.5
- Web Forms
Кроме того, когда я вернулся обратно в 5.0.0.beta2, без каких-либо других изменений, она работает еще раз. Так что это определенно изменение в Microsoft.AspNet.WebApi
. Я в порядке с внесением изменений в код, мне просто нужны советы. Благодаря!