c# - ASP.Net 中的自定义角色提供程序是否为使用 Windows 身份验证的每个用户实例化?

标签 c# asp.net asp.net-mvc

我为 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/

相关文章:

c# - 捕捉 "Maximum request length exceeded"

c# - 为 asp.net MVC 静态资源设置合成路由

c# - 选择随机颜色,特定颜色除外

asp.net - URL 路由、图像处理程序和 "A potentially dangerous Request.Path value"

c# - 将 DataTable 转换为 IEnumerable<T>

asp.net - 使用 DI DbContext 和使用 LINQ 的模型对 Controller 进行单元测试 - EF Core 2

sql-server - 从SQL Server加载数据以进行 Elasticsearch

c# - 如何根据某些条件更改 MVC webgrid 行文本的颜色

c# - 在 C# Tcp 服务器中调试可能孤立的套接字

c# - 如何在字典初始化中声明事件?