asp.net core - vNext Owin Middleware -
i have simple middleware:
public class middlewareinterceptor { requestdelegate _next; public middlewareinterceptor(requestdelegate next) { _next = next; } public task invoke(httpcontext ctx) { ctx.response.writeasync("<h2>from somemiddleware</h2>"); return _next(ctx); } }
and in startup.cs configure method, hook so:
app.usemiddleware<middlewareinterceptor>();
the above builds , app seems run fine, breakpoint in interceptor invoke method never hits. , likewise, there never output. tried debug.writeline
also.
now, tried method:
public class middlewareinterceptor : owinmiddleware { public middlewareinterceptor(owinmiddleware next) : base(next){} public override async task invoke(iowincontext context) { debug.writeline(context.request.uri.tostring()); await next.invoke(context); } }
and in startup.cs configure method, hook so:
app.use(next => new middlewareinterceptor(next).invoke);
unfortunately, base owinmiddleware
constructor looking next owinmiddleware
parameter, unlike ye olde requestdelegate
. app.use
instantiation of middlewareinterceptor
fails because next
of type requestdelegate
.
lastly, have tried inline function directly in configure method never hits breakpoint:
app.use(async (ctx, next) => { system.diagnostics.debug.writeline("hello"); await next(); });
so stands, seems cant make basic middleware interceptor using owin. missing?
what order of aforementioned middleware in pipeline? make sure executes before terminate request part of pipeline; eg. usemvc();
Comments
Post a Comment