正如官方所说document https://learn.microsoft.com/en-us/aspnet/core/fundamentals/owin,我正在尝试实施UseOwin
in the Startup.cs.
我正在尝试使用/端口IAppBuilder (Microsoft.Owin.Builder.AppBuilder)
inside IApplicationBuilder (Microsoft.AspNetCore.Builder.IApplicationBuilder)
。我使用以下代码编写了遗留代码IAppBuilder
在 .Net Framework 4.5 上运行良好。
我见过几个关于在 IAplicationBuilder 中使用 IAppBuilder 的示例,例如示例1 https://www.codeproject.com/Articles/1122162/Implement-Owin-Pipeline-using-Asp-net-Core 示例2 https://github.com/tusdotnet/tusdotnet/wiki/Troubleshoot:-%22'IApplicationBuilder'-does-not-contain-a-definition-for-'UseTus'%22-in-ASP.NET-Core。这些尝试是关于 .netcore 1.1 而不是 .net core 2.0。可能这就是我无法移植的原因。
请分享您的想法,无论我是想在 .net core 2.0 中实现目前不可能实现的目标,还是我的代码中存在一些错误。
笔记:
我在用dotnetcore 2.0
with Visual Studio 2017
Error
我收到以下错误。
返回owinAppBuilder.Build,
任务>>(); TypeLoadException:无法加载类型
程序集中的“System.Security.Cryptography.DpapiDataProtector”
'系统.安全性,版本=4.0.0.0,文化=中性,
PublicKeyToken=b03f5f7f11d50a3a'。
我的尝试
app.UseOwin(setup => setup(next =>
{
var owinAppBuilder = new AppBuilder();
var aspNetCoreLifetime =
(IApplicationLifetime)app.ApplicationServices.GetService(typeof(IApplicationLifetime));
new AppProperties(owinAppBuilder.Properties)
{
OnAppDisposing = aspNetCoreLifetime?.ApplicationStopping ?? CancellationToken.None,
DefaultApp = next,
AppName = "test"
};
// Only required if CORS is used, configure it as you wish
var corsPolicy = new System.Web.Cors.CorsPolicy
{
AllowAnyHeader = true,
AllowAnyMethod = true,
AllowAnyOrigin = true,
SupportsCredentials = true
};
//corsPolicy.GetType()
// .GetProperty(nameof(corsPolicy.ExposedHeaders))
// .SetValue(corsPolicy, tusdotnet.Helpers.CorsHelper.GetExposedHeaders());
owinAppBuilder.UseCors(new Microsoft.Owin.Cors.CorsOptions
{
PolicyProvider = new CorsPolicyProvider
{
PolicyResolver = context => Task.FromResult(corsPolicy)
}
});
PublicClientId = "self";
OAuthAuthorizationServerOptions OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new Microsoft.Owin.PathString("/Login"),
Provider = new MyServiceProvider(PublicClientId),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(60),
AllowInsecureHttp = true,
RefreshTokenProvider = new MyRefreshTokenProvider(),
};
owinAppBuilder.UseOAuthBearerTokens(OAuthOptions);
//owinAppBuilder.UseTus(context => new DefaultTusConfiguration
//{
// // Excluded for brevity, use the same configuration as you would normally do
//});
return owinAppBuilder.Build<Func<IDictionary<string, object>, Task>>();
}));