c# - 是否可以覆盖 HostAuthenticationFilter 过滤器?

标签 c# asp.net-web-api owin bearer-token authorize-attribute

是否可以覆盖 HostAuthenticationFilter 过滤器来自定义响应消息?

配置如下: 它是不记名 token 授权。

config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

最佳答案

您可以通过这种方式覆盖:

public class HostAuthenticationFilterCustom : HostAuthenticationFilter
    {
        public HostAuthenticationFilterCustom(string authenticationType) : base(authenticationType)
        {
        }
        public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
        {
            return base.AuthenticateAsync(context,cancellationToken);
        }
        public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
        {
            return base.ChallengeAsync(context,cancellationToken);
        }
    }

关于c# - 是否可以覆盖 HostAuthenticationFilter 过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49203074/

相关文章:

c# - StatusCode : 404, ReasonPhrase : 'Not Found' , 版本 : 1. 1,

OpenId 连接 Owin 中间件与 Orchard CMS 1.9.2

c# - 使用包含 EF 时可能的 SQL 注入(inject)?

asp.net - 在 Web API 中使用 Route 属性的可选参数?

c# - EF : manual (non autogenerated) keys require ad hoc handling of new entities

android - 从 Android 到 Web API 的 POST 数据返回 404

c# - Owin 托管的 webapi 2.2。使用模拟服务测试 Controller

c# - ASP.NET Identity 不会根据同一请求更新身份信息

c# - 单元测试需要读取文件。我如何使其便携?

c# - 我将如何创建 Windows Phone Live Camera Feed?