우리 프로젝트에서 조건부 미들웨어를 구현하는 this 문서를 따라하고 완벽하게 잘 작동했다. 하지만 우리는 .netcore 1.0에서 .netcore 1.1로 프로젝트를 업그레이드 했으므로 작동하지 않습니다.조건부 - 미들웨어 - in - aspnet 코어 asp.net 코어 1.1에서 작동하지 않습니다
저는 시작시에 다음 코드를 작성했습니다.
Func<HttpContext, bool> isApiRequest = (HttpContext context) => context.Request.Path.ToString().StartsWith("/api/");
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
//For MVC not API
app.UseWhen(context => !isApiRequest(context), appBuilder =>
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookies",
AutomaticAuthenticate = true
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
AuthenticationScheme = "oidc",
SignInScheme = "Cookies",
AutomaticChallenge = true,
Authority = authority,
RequireHttpsMetadata = false,
ClientId = "sampleClient",
//ClientSecret = "secret",
Scope = { "openid" , "profile" },
ResponseType = "id_token token",//"code id_token",
SaveTokens = true
});
});
//FOR API
app.UseWhen(context => isApiRequest(context), appBuilder =>
{
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions()
{
Authority = authority,
RequireHttpsMetadata = false,
AllowedScopes =
{
"scope1",
"scope2"
}
});
});
는 지금은 기반 인증을 쿠키하지, 심지어 조건 API를 인증 작업에보기를 기반으로 ActionMethod를 (API로 시작하지 의미)에 액세스하려고 할 때. 그리고 API 기반 인증은 완벽하게 작동합니다.
우리는 신원 서버 4.
어떤 도움의 최신 버전에 우리의 프로젝트를 구축하고는/포인터는 이해할 수있을 것이다.
당신은 사용하지 않는해야'appBuilder' 대신'app'의 조건 분기 안에? 그냥 생각, 그것은 이상하게 보입니다. – juunas
정말 이상합니다. config 함수는 시작할 때 실행되기 때문에 ** 그것은 조건이 존재하지 않는 것처럼 모든 미들웨어를 등록합니다 **. – juunas
그냥 VS2017 .net core 1.1에서 같은 문제가 발생했습니다. 주어진 대의원은 결코 처형 된 것처럼 보이지 않습니다. – NoSaidTheCompiler