views:

138

answers:

1

If I implement my own CustomPrincipal in asp.net mvc, must I use a Custom ActionFilterAttribute to check for Roles that my users belong to (like this: http://www.codethinked.com/post/2008/04/01/Setting-up-authentication-in-aspnet-MVC.aspx)???.

When I use:

[Authorize]

It works fine. But when I use:

[Authorize(Roles=("Example"))]

It goes off and looks for

"dbo.aspnet_CheckSchemaVersion"

Which I obviously don't have since I haven't added the asp.net membership objects to my database, I'm writing my own.

I'm using asp.net mvc 2 beta.

Edit: How can I override the logic that the default attributes uses so that I can use the same tag: [Authorize(Roles=("Example"))]

A: 

The attribute your using will try and use the default RoleProvider to find out what role that user is in.

In the article he outlines creating a custom [UserInRole("Admin")] attribute that avoids the RoleProvider and uses custom logic to determine what role the user is in.

Here is a good MSDN article about implementing your own RoleProvider: http://msdn.microsoft.com/en-us/library/8fw7xh74.aspx

Edit Answer: Your going to have to implement your own roleprovider or create your own custom tag. Your custom tag can look similar to the one baked into MVC but you can't just match signatures and hope to override it that way.

jfar
How can I override the logic that the default attributes uses so that I can use the same tag: [Authorize(Roles=("Example"))]
hminaya
You simply can't. You'll have to create a custom attribute or role your own role provider.
jfar
Ok. thanks. I just wanted to make sure before going ahead.
hminaya