Pio*_*app 2 asp.net owin asp.net-core
TL; DR;
有没有一种方法可以在.NET Standard中创建与Microsoft.Owin向后兼容的Owin中间件?
细节
我创建了一个简单的中间件,例如:
public class RequestTrackingMiddleware
{
private readonly RequestDelegate _next;
public RequestTrackingMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
var sw = Stopwatch.StartNew();
await _next(context);
sw.Stop();
Console.WriteLine(sw);
}
Run Code Online (Sandbox Code Playgroud)
我将它与Owin一起添加到“经典” ASP.NET应用程序中。使用方法:
public override void Configuration(IAppBuilder app)
{
app.Use<FinaiRequestTrackingMiddleware>();
}
Run Code Online (Sandbox Code Playgroud)
但我最终得到:
Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2 [....]和Microsoft.AspNetCore.Http.RequestDelegate之间没有可用的转换。
有任何想法吗?
是的,您可以,但是不是OWIN中间件,而是ASP.NET Core中间件。请参阅此博客文章http://benfoster.io/blog/how-to-write-owin-middleware-in-5-different-steps(步骤3最相关)。然后,您可以在Katana或ASP.NET Core中使用该OWIN中间件(通过OWIN桥),以https://codeopinion.com/migrate-from-katana-asp-net-core/为例。
| 归档时间: |
|
| 查看次数: |
2163 次 |
| 最近记录: |