Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9018231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:28:23+00:00 2026-06-16T04:28:23+00:00

I have the following test setup, all working: -WCF Application running a MathService.svc, setup

  • 0

I have the following test setup, all working:

-WCF Application running a MathService.svc, setup to use SimpleMembershipProvider

-MVC 4 Internet App using the default SimpleMembershipProvider

-Membership is:

  • 3 Roles: ‘Debug’, ‘Administrator’ and ‘Editor’
  • 2 Users: ‘Debug’ in Role Debug and Administrator (ya, user debug in role debug)
  • ‘Admin’ in Role Administrator

-Certificates, as far as I can tell are working, I can connect to the service using wshttp

Service Method Code.

//[PrincipalPermission(SecurityAction.Demand, Role = "Debug")]
public string Add(double A, double B)
{
    OperationContext oc = OperationContext.Current;
    ServiceSecurityContext ssc = oc.ServiceSecurityContext;
    string cltName = ssc.PrimaryIdentity.Name;   //cltName = "Debug"
    var Rs = Roles.GetAllRoles(); //returns: 'Debug', 'Administrator', 'Editor' => OK
    var dUsers = Roles.GetUsersInRole("Debug");  // 'Debug' => Expected
    var aUsers = Roles.GetUsersInRole("Administrator"); // 'Debug', 'Admin' => expected
    try
    {
        var a = Roles.GetRolesForUser(cltName); //this fails 
        var b = Roles.IsUserInRole(cltName, "Debug"); //this fails 
        var c = Roles.IsUserInRole(cltName, "Administrator"); //this fails 
    }
    catch (Exception err)
    {
        string p = err.Message; // all fail with error :
        // "Object reference not set to an instance of an object", inner exception=null
    }
    if (dUsers.Contains(cltName)) //this works, but requires extra step 
        //I should be able to us if(Roles.IsUserInRole(cltName, "Debug"))... here?!?
    {
        return string.Format("Result: {0}", (A + B).ToString("N2"));
    }
    else
    {   //this is just to get a different result if NOT in role 'Debug'
        return string.Format("Result: {0}", ((int)A + (int)B).ToString("N2"));  
    }
}

Why are calls to’ Roles.GetRolesForUser(cltName)’ and IsUserInRole failing?

I get the correct username from ‘ServiceSecurityContext’,
If I enable the [PrincipalPermission] attrib I get rejected if I call the service with user Admin, as expected.

So why would PrincipalPermission be able to get the correct user role?
Why can I use Roles.GetUsersInRole(“Debug”) to get all correct users
BUT I can not call Roles.IsUserInRole(..)??

There are some posts suggesting certificate / /membership setup errors, but I can not see how I can get so far and still have a wrong setup, and above all, just SOME of the Roles methods fail, not all. Any pointers?

A word about the return result, If I use my Role workaround and call via Debug, the service returns double precision, if I call with admin [PrincipalPermission] disabled, I get integer precision back

Regards, Andreas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:28:25+00:00Added an answer on June 16, 2026 at 4:28 am

    Just in case anyone runs into the same problem.

    While you can use the ‘old’ ASP.net RolesProvider with simpleMembership, they are not the same.

    In my case, I had to add a simple cast.

    var _simpleRoles = (SimpleRoleProvider)Roles.Provider; //need the cast to simple
    

    and then this works

     var b = simpleRoles.IsUserInRole(cltName, "Debug"); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Coldfusion, the CF administrator and my test site all setup and working
I have the following test case in my iOS application : -(void) testTwoDefaultUsersExist {
Good day to all. I have the following setup: A page with html, js,
I have the following unit test in my application: [TestMethod] public void Windsor_Can_Resolve_HomeController_Dependencies() {
After I have set up all the unit test cases for my android application
I have following test.pyx cdef public class Foo[object Foo, type FooType]: cdef public char*
I have following test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {/services-test-config.xml}) public class MySericeTest { @Autowired
suppose I have following test/ Main.py test/one/ One.py test1.txt test/two/ Two.py test2.txt What I
I have following databases: test table1 fields: id, password, name, lastname test2 table2 fields:
I have following string: Test, User < test@test.com >, Another, Test < another@test.com >,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.