What is the most elegant way to verify method permissions (C # .Net)

I have a WebService built into WCF (C # .Net) that contains dozens of methods. On all methods, I did not check if the current user has access to this specific action.

I now have something like this:

public MyContract MyMethod(int MyParameter) { ValidateAccess(MyCurrentIdentityInfo, ActionEnum); // Do stuff here... } public void MyMethod2(int MyParameter) { ValidateAccess(MyCurrentIdentityInfo, ActionEnum); // Do stuff here... } etc... 

You will notice that I first call the method to check the permissions, and then execute the code that I need. This code works fine, but I have to call this method for every method in my service, and I haven't found it enough.

Is there a more elegant way to achieve what I'm trying to do? I tried to use a custom attribute but could not.

Please note that I am NOT trying to authenticate the user in the WebService itself . In the above example, the user will act in the WebService. But I would like to run my own code to check if it can call a method that deletes a record, for example.

+4
source share
1 answer

You can use the Dynamic Proxy Lock to enter an operation confirmation for a registered user.

+1
source

Source: https://habr.com/ru/post/1415635/


All Articles