对服务合同的PrincipalPermission属性 [英] PrincipalPermission attribute on Service contract

查看:125
本文介绍了对服务合同的PrincipalPermission属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个技术之所以能的PrincipalPermission不能放在一个服务合同接口?它仅适用于类直接在类方法实现合同或。

Is there a technical reason why a PrincipalPermission can't be placed on a service contract interface? It only works on the class implementing the contract or directly on the class methods.

这是行不通的。

[ServiceContract]
public interface IMyService
{
    [PrincipalPermission(SecurityAction.Demand, Role="Admin")]
    [OperationContract]
    void MyFunction(string str);
}

但它的工作原理,如果我把属性上的类实现IMyService的匹配方法。

But it works if I place the attribute on the matching method in the class implementing IMyService.

推荐答案

中的作用是检查在运行时,用戴上实现方法,没有把该接口上的方法实现的属性的属性。更一般地在.NET中没有放在一个方法和自定义属性放在相应的接口方法,如果有自定义属性之间的直接关系。

The role is checked at runtime, using the attributes put on the implementing method, not the attributes put on the interface the method implements. More generally in .NET there is not direct relation between custom attributes put on a method and custom attributes put on the corresponding interface method, if any.

这篇关于对服务合同的PrincipalPermission属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆