Search code examples
asp.netasp.net-mvcowinkatana

Enumerate all OWIN keys and values


How can you list out all OWIN keys and their values, similar to Request.ServerVariables in WebForms:

foreach(string k in Request.ServerVariables)
{
    Debug.WriteLine("{0}: {1}", k, Request.ServerVariables[k]);
}

Solution

  • I thought I would find this Googling but did not; the code is pretty straight forward after digging in with IntelliSense. It is based on owinContext.Environment.Keys

    var owinContext = HttpContext.GetOwinContext();
    foreach (string k in owinContext.Environment.Keys)
    {
        Debug.WriteLine("{0}: {1}", k, owinContext.Environment[k]);
    }