我为 ASP.Net MVC 编写了一个自定义角色提供程序。我正在调用 WCF 服务来获取角色来授权当前用户。我正在使用 Windows 身份验证。
我想将当前用户角色存储在角色提供程序类的变量中,但不清楚该类是按 session 还是按应用程序创建。
最佳答案
它被实例化一次。快速查看文档证实了这一点:
For each role provider specified in the configuration for an application, ASP.NET instantiates a single role-provider instance that is used for all of the requests served by an HttpApplication object. As a result, you can have multiple requests executing concurrently. ASP.NET does not ensure the thread safety of calls to your provider. You will need to write your provider code to be thread safe. For example, creating a connection to a database or opening a file for editing should be done within the member that is called, such as AddUsersToRoles , rather than opening a file or database connection when the Initialize method is called.
关于c# - ASP.Net 中的自定义角色提供程序是否为使用 Windows 身份验证的每个用户实例化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1436026/