Query intercettore su tutte le entità
-
21-12-2019 - |
Domanda
È possibile creare un nome personalizzato query intercettore in un dato WCFServizio su tutte le entità invece di solo uno?Questo è un query intercettore standard:
[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;
}
.
Mi piace fare qualcosa del genere:
[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;
}
.
C'è qualche modo o devo integrare un in eccesso per tutte le mie entità?
Soluzione
Sfortunatamente non è possibile utilizzare una wild card con il query intercettore, tuttavia è possibile ottenere lo stesso risultato del tuo esempio, sovrascrivendo il metodo OnStartProcessingRequest del DataService e controllando il ruolo dell'utente.
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);
}
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow