本文介绍了参考当前的RoleProvider实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET页,带有 HttpContext 当前,如何获得对当前 RoleProvider 实例?

When inside an ASP.NET page, module or handler with an HttpContext present, how do I get a reference to the current RoleProvider instance?

调用IPrincipal.IsInRole(..)方法.默认情况下或通过配置,我的提供程序似乎是SqlRoleProvider 实例由我在运行应用程序时给出的错误引起.

It's the provider used for authorization when the IPrincipal.IsInRole(..) method is called. By default, or from configuration, my provider seems to be a SqlRoleProvider instance by an error given when I'm running the app.

我想在运行时检查提供程序的类型,以提供有关实际使用哪个提供程序的反馈.

I want to inspect the type of provider at runtime to provide feedback on which one is actually being used.

推荐答案

静态角色类上具有Provider属性,您可以使用该属性来引用当前的提供程序.

The static Roles class has a Provider property on it which you can use to reference the current provider.

Roles.Provider

,如果您使用的是自定义RoleProvider,则可以对其进行强制转换以访问自定义功能.

and if you are using a custom RoleProvider, you can cast it in order to access custom functionality.

((MyCustomRoleProvider)Roles.Provider).AllYourRoleAreBelongToUs();

这篇关于参考当前的RoleProvider实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 22:37