When I register middleware as part of the request pipeline, how do I pass data through the middleware chain. (ultimately accessible in an MVC controller action)
For exam
You can store custom data in IOwinContext object. IOwinContext object can be accessed from Invoke function of your middleware.
Set
context.Set<T>("key", obj);
Get
var obj = context.Get<T>("key");
You can use the HttpContext.Items
collection to store data for the lifetime of a request. Its primary use-case is passing data around components (middleware and controllers for example). Adding and reading items is easy:
Write:
context.Items["AuthData"] = authData;
Read:
var authData = (AuthData)context.Items["AuthData"];
See the ASP.NET docs for more info.