I'm having a weird issue regarding Owin and its context. I have a controller action that looks like this
[HttpPost]
public ActionResult Login(string username, string password)
{
var ctx = HttpContext.GetOwinContext();
// code omitted
return new HttpUnauthorizedResult();
}
If I set a breakpoint at var ctx
and debug my application the variable gets its value. But if just start the applicaiton normally and run it with IIS Express (ctrl+f5) the application breaks at var ctx
and gives me the error.
"No owin.Environment item was found in the context."
What's causing this error?
I'm running this in Visual Studio 2013, .Net version 4.5.1. Thanks for your help!
Please let me know if you think you need more code from startup.cs or anywhere else.
EDIT: This is my startup conf.
[assembly: OwinStartup(typeof(XXX.Startup))]
namespace XXX
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
namespace XXX
{
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = AuthenticationTypes.Cookie,
AuthenticationMode = AuthenticationMode.Active,
SlidingExpiration = true,
ExpireTimeSpan = new TimeSpan(0, 30, 0),
});
app.UseMyAuthentication(new MyAuthenticationOptions()
{
AuthenticationType = AuthenticationTypes.MyAuthType,
SignInAsAuthenticationType = AuthenticationTypes.Cookie,
AuthenticationMode = AuthenticationMode.Passive,
CallbackPath = new PathString("/authorization/callback")
});
}
}
}