经常被引用的参考框架是兼容的an extension method build by Thinktecture for supporting their IdentityServer3 on ASP.NET 5。
该方法特定于IdentityServer,并且不支持稍后在AspNet管道中注册的任何中间件处理的请求(它不会调用下一个组件)。
此相适应的方法来解决这些不足之处:
internal static class IApplicationBuilderExtensions
{
public static void UseOwin(
this IApplicationBuilder app,
Action<IAppBuilder> owinConfiguration)
{
app.UseOwin(
addToPipeline =>
{
addToPipeline(
next =>
{
var builder = new AppBuilder();
owinConfiguration(builder);
builder.Run(ctx => next(ctx.Environment));
Func<IDictionary<string, object>, Task> appFunc =
(Func<IDictionary<string, object>, Task>)
builder.Build(typeof(Func<IDictionary<string, object>, Task>));
return appFunc;
});
});
}
}
它可以如下使用:
app.UseOwin(
owin =>
{
// Arbitrary IAppBuilder registrations can be placed in this block
// For example, this extension can be provided by
// NWebsec.Owin or Thinktecture.IdentityServer3
owin.UseHsts();
});
// ASP.NET 5 components, like MVC 6, will still process the request
// (assuming the request was not handled by earlier middleware)
app.UseMvc();
我不明白完整的含义,但这是有效的,并且由于额外的财产分配,似乎可能更健壮。只是为了确保我没有遗漏某些东西,这个实现还需要引用'Microsoft.Owin'使得实现在这方面是相同的? – vossad01
当然,它取决于AppBuilder,它是Microsoft.Owin的一部分。试图重构它以避免引用Microsoft。Owin是一个很好的练习,但我不确定这是否值得,因为您仍然需要将您想使用的OWIN/Katana中间件移植到Core CLR。 – Pinpoint
断开链接.... –