In meinem Produktionscode haben wir ein Problem, wo Request.GetOwinContext() immer Null zurückgibt.ASP.Net WebAPI OWIN: Warum würde Request.GetOwinContext() null zurückgeben?
ich Setup ein kleiner Test WebAPI Controller und zu isolieren, um das Problem zu versuchen:
public class TestController : ApiController
{
[HttpGet]
public async Task<IHttpActionResult> GetAsyncContext(string provider)
{
if (HttpContext.Current.GetOwinContext() == null)
return this.BadRequest("No HttpContext.Current Owin Context");
if (Request.GetOwinContext() == null)
return this.BadRequest("No Owin Context");
return this.Ok();
}
[HttpGet]
public IHttpActionResult GetContext(string provider)
{
if (HttpContext.Current.GetOwinContext() == null)
return this.BadRequest("No HttpContext.Current Owin Context");
if (Request.GetOwinContext() == null)
return this.BadRequest("No Owin Context");
return this.Ok();
}
}
Zuerst dachte ich, es hat etwas mit der Aktion-Methode läuft asynchron zu tun haben könnte, aber nach dem oben ausgeführt, stellt sich In beiden Versionen gibt Request.GetOwinContext() null zurück.
Ich verwende Microsoft.AspNet.WebApi.Owin.5.1.1 (das ist, wo es die GetOwinContext() Erweiterungsmethode scheint definiert ist).
Alle Ideen, was hier passiert ???
Sind Sie sicher, dass die Startup-Klasse aufgerufen wird und alle Module registriert sind? – William