QueryInterceptor在所有实体上
-
21-12-2019 - |
题
是可以制作自定义 queryinterceptor 在WCF数据中所有regites的服务而不是一个只有一个?这是一个标准的QueryInterceptor:
[QueryInterceptor("Products")]
public Expression<Func<Product, bool>> OnQueryProducts()
{
var user = HttpContext.Current.User;
if (user.IsInRole("Administrator"))
return (Product p) => true;
else
return (Product p) => false;
}
.
我喜欢这样做:
[QueryInterceptor("*")]
public Expression<Func<Object, bool>> OnQueryProducts()
{
var user = HttpContext.Current.User;
if (user.IsInRole("Administrator"))
return (Object p) => true;
else
return (Object p) => false;
}
.
是有什么方法还是我必须为我的所有实体集成一个人的一个人?
解决方案
不幸的是,您无法使用QueryInterceptor使用通配符,但是,您可以通过覆盖DataService的onstartProcessingRequest方法并检查用户的角色来实现与您的示例中的相同的结果。
protected override void OnStartProcessingRequest(ProcessRequestArgs args)
{
var user = HttpContext.Current.User;
// Only Administrator users are allowed access
if (!user.IsInRole("Administrator"))
{
// Any other role throws a security exception
throw new SecurityException("You do not have permission to access this Service");
}
base.OnStartProcessingRequest(args);
}
. 不隶属于 StackOverflow