How do I restrict access to some methods in WCF?

后端 未结 2 659
遥遥无期
遥遥无期 2020-12-13 15:37

I am a bit lost getting started with a simple WCF service. I have two methods and I want to expose one to the world and the second one I want to limit to certain users. Ev

2条回答
  •  攒了一身酷
    2020-12-13 16:25

    Use the following steps to restrict access to specific Windows users:

    • Open the Computer Management Windows applet.
    • Create a Windows group that contains the specific Windows users to which you wish to give access. For example, a group can be called “CalculatorClients”.
    • Configure your service to require ClientCredentialType = “Windows”. This will require clients to connect using Windows authentication.
    • Configure your service methods with the PrincipalPermission attribute to require connecting users be members of the CalculatorClients group.
    // Only members of the CalculatorClients group can call this method.
    [PrincipalPermission(SecurityAction.Demand, Role = "CalculatorClients")]
    public double Add(double a, double b)
    { 
    return a + b; 
    }
    

提交回复
热议问题