简体   繁体   English

覆盖 .net 核心中的 UseAuthorization 行为

[英]Overriding UseAuthorization behaviour in .net core

In the asp.net core application, I want to write Authorization middleware on my own.在asp.net核心应用中,我想自己写授权中间件。 I am trying to implement it similar to Example 2. But if I try to use I get compilation error saying " IApplicationbuilder doesnt contain a definition of UseAuthorization "我正在尝试以类似于示例 2 的方式实现它。但如果我尝试使用,我会收到编译错误消息“ IApplicationbuilder 不包含 UseAuthorization 的定义

How to add my custom method to IApplicationBuilder?In which file I need to add my method?.如何将我的自定义方法添加到 IApplicationBuilder?我需要在哪个文件中添加我的方法?。

Startup.cs启动.cs

public void Configure(IApplicationBuilder app,IHostingenvironment env)
{
 app.UseAuthorization();
}

Example 2:示例 2:

public static IApplicationBuilder UseAuthorization(this IApplicationBuilder app)
{
 return app.UseMiddleware<AuthorizationMiddleware>();
}

Go the definition of your UseAuthorization to check whether you install sdk of Asp.Net Core. Go 定义你的UseAuthorization来检查你是否安装了 Asp.Net Core 的 sdk。

在此处输入图像描述

If not, you could install and rebuild again.如果没有,您可以重新安装和重建。

Downloads for .NET Framework and .NET Core, including ASP.NET and ASP.NET Core .NET 框架和 .NET 内核的下载,包括 ASP.NET 和 ASP.NET 内核

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

相关问题 无法识别 ASP.Net Core `UseAuthorization` - ASP.Net Core `UseAuthorization` not recognized 使用剃须刀页面覆盖.net Core 2中的授权策略 - overriding an authorization policy in .net core 2 with razor pages 覆盖ASP.NET Core中的appsettings值 - Overriding appsettings values in asp.net core ASP.NET Core - 覆盖默认的 ControllerFactory - ASP.NET Core - Overriding the default ControllerFactory .NET Core身份-脚手架页面,不会覆盖现有文件 - .NET Core Identity - Scaffold pages without overriding existing files .Net Core ConfigureAppConfiguration 添加额外的资源覆盖环境特定设置 - .Net Core ConfigureAppConfiguration adding additional sources overriding environment specific settings Newtonsoft.Json 在 .NET 5 / 核心和 .NET 框架上的不同行为 - Different behaviour of Newtonsoft.Json on .NET 5 / Core and .NET Framework .NET 核心和 .NET 框架中 HttpWebRequest/HttpClient 的不同行为 - Different behaviour of HttpWebRequest/HttpClient in .NET Core and .NET Framework 覆盖不适用于ASP.net Core MVC中的虚拟方法 - Overriding does not work on virtual method in ASP.net Core MVC 覆盖ASP.NET Core ResourceFilter中的BadRequest响应 - Overriding BadRequest response in ASP.NET Core ResourceFilter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM