ASP.NET - 在身份验证属性中访问数据库表

时间:2017-06-03 18:43:40

标签: c# asp.net asp.net-mvc entity-framework

我正在使用本教程构建ASP.NET Web API 2(MVC 6)应用程序:http://bitoftech.net/2014/12/15/secure-asp-net-web-api-using-api-key-authentication-hmac-authentication/

一切都很顺利,但现在我想访问ApplicationsUsers中的HMACAuthenticationAttribute表。我怎样才能做到这一点?是否将allowedApps字典设为公共静态,并将每个刚注册的用户添加到此字典中唯一可能的解决方案?我如何在这里访问dbcontext?

对于不想阅读该教程的人:我需要在IAuthenticationFilter中访问dbcontext。怎么做?

1 个答案:

答案 0 :(得分:0)

您可以在DbContext课程中创建HMACAuthenticationAttribute的变量 如果你的应用程序要创建大量的应用程序ID,我不建议让allowedApps作为静态变量。它可能是公共变量。但我建议通过单独的方法添加字典,这样您就可以更好地控制插入allowedApps

的内容