jjzjj

IAuthorizationFilter

全部标签

c# - ASP.NET IAuthorizationFilter OnAuthorization

您好,我正在尝试实现自定义授权过滤器//TheAuthourizationattributeonacontrollerpublicclassCustomAdminAuthorizationFilter:IAuthorizationFilter{privatereadonlyIAuthentication_authentication;publicSageAdminAuthorizationFilter(IAuthenticationauthentication){_authentication=authentication;}publicvoidOnAuthorization(Auth

c# - 如果我想使用 ASP.NET MVC4 创建 ApiKey 受限资源,我应该使用 IAuthorizationFilter 吗?

我有一些简单的路由,我希望通过一个简单的查询字符串参数来限制它们。如果key不正确或未提供,那么我希望抛出一个NotAuthorizedException。请不要建议我使用WebApi或等价物-在这种情况下我还不能。所以我不确定我是否应该实现IAuthorizationFilter或实现IActionFilter或什至其他东西。我的代码逻辑?检查查询字符串中的键。检查我的RavenDb(存储库)是否有具有该键/值的用户。如果他们未通过任何这些检查,则抛出NotAuthorizedException。我假设我会用这个过滤器装饰我的操作方法。我还假设我还需要将我的存储库传递到此操作方法中?