There are two functions. Let's implement them. How can we handle exceptions?
Roles. addusertorole (user, role); What should I do if the user is already a role?
Roles. removeuserfromrole (user, role); What should I do if user is no longer a role?
In the past, we have encountered such situations. In both cases, we can naturally release them, because the goal has been achieved. Why should we consider the past situation? But in fact, both functions are self-contained functions in Asp.net, and two exceptions are returned respectively.
From the technical implementation point of view, this is redundant, but from the application point of view, the more you think, the more reasonable.
Assume that this is an application system.CodeAfter receiving a command to authorize or unauthorize a user who has been authorized or unauthenticated, it is very likely that there is a problem with the judgment logic, in addition, the authorization information displayed on the view is incorrect. Therefore, an operation link that is not supposed to exist is generated (MVC is used, and the link is the operation ). It is necessary to remind users that the appearance you see is different from the actual situation! Instead of simply solving it technically, otherwise there will be some wrong authorization situations in other places.
Click to download the free agile development textbook: Martian agile development manual