views:

52

answers:

1

Hello friends,

I have created my own custom role provider class "SGI_RoleProvider" and configured properly. Everything is working fine.

Suppose that I have added a public method say "SayHello()", then how can i call that. Because if i am using Roles then the method is not displayed. If i am forcefully using that Roles.SayHello() then compiler gives the error.

Any suggestion how can i call this. Because creating a new instance of SGI_RoleProvider is meaningless.

Thanks for sharing your time.

+1  A: 
var myProvider = Roles.Provider as SGI_RoleProvider;
myProvider.SayHello();

Supposing you have correctly defined your provider as the default Provider

uvita
thanks buddy! But even casting does not work here because Roles is a static class. By the way i m using c#.
IrfanRaza
I tested this code and it works, I am not casting the Roles class but the Provider property of the Roles class which is of type RoleProvider. See http://msdn.microsoft.com/en-us/library/system.web.security.roles.provider.aspx. The code I wrote is C#, maybe you're using framework 2.0, so you can writeCustomProvider myProvider = Roles.Provider as CustomProvider;myProvider.SayHello();instead.Good luck!
uvita
Great!!! Thanks uvita! It works. Actually I forget to use Provider property. I was casting Roles. Yes I was considering the code in VB.
IrfanRaza