Earlier this week I ended up in a situation where, a signal flag wanted to be set in a controller method which will eventually invoke the RedirectToIdentityProvider
notification where the signal flag value has to be checked and retrieved. Usually the RedirectToIdentityProvider
notification is getting called when SignIn()
, SignOut()
or Challange()
methods are getting called.
I was trying different mechanisms to solve the problem and finally found OWIN Environment is really handy to solve this. So in the place where I wanted to set the flag,
HttpContext.GetOwinContext().Environment.Add("flag", "true");
later which was called inside RedirectToIdentityProvider
notification Func as below
object obj = null;
if (context.OwinContext.Environment.TryGetValue("flag", out obj))
{
string flag = obj as string;
// operations below
}
One use-case in this approach is that its really easy to late-bind Authentication related properties without hassle.
Happy coding.
Leave a comment