简体   繁体   English

无法识别 ASP.Net Core `UseAuthorization`

[英]ASP.Net Core `UseAuthorization` not recognized

I have the following code in my Configure method that is giving a warning:我的Configure方法中有以下代码发出警告:

授权警告

It says:它说:

The call to UseAuthorization should appear between app.UseRouting() and app.UseEndpoints(..) for authorization to be correctly evaluated.对 UseAuthorization 的调用应该出现在 app.UseRouting() 和 app.UseEndpoints(..) 之间,以便正确评估授权。

It clearly is between those calls.显然是在这些调用之间。 I would assume that it is mistaken and move on, but when I call my service operations I get this error:我会假设它是错误的并继续前进,但是当我调用我的服务操作时,我收到此错误:

验证错误

The code will not run because it thinks that my UseAuthorization is not between UseRouting and UseEndpoints .代码将不会运行,因为它认为我的UseAuthorization不在UseRoutingUseEndpoints之间。

I am stumped!我难住了! Not sure what I need to change to make this work.不知道我需要改变什么才能完成这项工作。 Any advice on what I am missing would be appreciated.关于我所缺少的任何建议将不胜感激。

Turns out that higher up in the Configure method I had this:事实证明,在Configure方法中我有这个:

app.UseMiniProfiler()
      .UseStaticFiles()
      .UseRouting()
      .UseEndpoints(endpoints =>
      {
          endpoints.MapDefaultControllerRoute();
      });

I ignored it because I thought it was all configuration for UseMiniProfiler , but it was actually chaining off the app to call UseRouting and UseEndpoints right in a row!我忽略了它,因为我认为它是UseMiniProfiler所有配置,但它实际上是链接app以连续调用UseRoutingUseEndpoints

Removing those calls fixed it!删除这些电话修复了它!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM