Roles

Jul 25, 2010 at 7:48 AM

I am trying to get roles working.

When I put on a DomainService Query the attribute [RequiresRole("Admin")]

the Services gets stuck on looking up the authentication in the default asp.net member database that does not exist.

System.Web.HttpException (0x80004005): Unable to connect to SQL Server database. ---> System.Web.HttpException (0x80004005): Unable to connect to SQL Server database. ---> System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

...

at System.Web.Security.SqlRoleProvider.GetRolesForUser(String username)
at System.Web.Security.RolePrincipal.IsInRole(String role)
at System.ServiceModel.DomainServices.Server.RequiresRoleAttribute.IsAuthorized(IPrincipal principal, AuthorizationContext authorizationContext)
at System.ComponentModel.DataAnnotations.AuthorizationAttribute.Authorize(IPrincipal principal, AuthorizationContext authorizationContext)
at System.ServiceModel.DomainServices.Server.DomainService.EvaluateAuthorization(IEnumerable`1 attributes, IPrincipal principal, AuthorizationContext authorizationContext)
at System.ServiceModel.DomainServices.Server.DomainService.IsAuthorized(DomainOperationEntry domainOperationEntry, Object entity)
at System.ServiceModel.DomainServices.Server.DomainService.ValidateMethodPermissions(DomainOperationEntry domainOperationEntry, Object entity)
at System.ServiceModel.DomainServices.Server.DomainService.ValidateMethodCall(DomainOperationEntry domainOperationEntry, Object[] parameters, ICollection`1 validationResults)
at System.ServiceModel.DomainServices.Server.DomainService.Query(QueryDescription queryDescription, IEnumerable`1& validationErrors, Int32& totalCount)

 

Why is it not looking for the roles in my AuthenticationService? I am overriding initialize like in your BookClub Example.

Jul 26, 2010 at 3:33 PM

Based on seeing things like RolePrincipal in your stack trace, it doesn't seem like a question related to this project. For general questions with RIA Services, please post on the appropriate forum.

As a quick answer based on your exception - make sure you've got the right connection string, and that things have been properly initialized in config and in the database.

Jul 26, 2010 at 4:46 PM
Thats whats weird about it. It is trying to use the standard Asp.Net Roles for a SQL Server that does not exist. My roles are mixed into my DataLayer that is why I am using your Book Club example. I think if you put a RequiresRole attribute in one of your BookClub Domain Services it will have the same problem as mine. To solve this I created a Custom RoleProvider and registered it in web.config. It was actually pretty easy. Perhaps you should add a RoleProvider to your RiaEssentials project that works with your base authentication service. As I think anyone who wants to use Roles with your authentication service (without creating custom Authorizaton Attributes) will need it.

-----Original Message-----
From: "nikhilk" <notifications@codeplex.com>
Sent: Monday, July 26, 2010 7:33am
To: [email removed]
Subject: Re: Roles [riaservices:221313]

From: nikhilk

Based on seeing things like RolePrincipal in your stack trace, it doesn't seem like a question related to this project. For general questions with RIA Services, please post on the appropriate forum.

As a quick answer based on your exception - make sure you've got the right connection string, and that things have been properly initialized in config and in the database.

Aug 11, 2010 at 6:26 AM
I do have roles support/usage in the application.