Yesterday I promised to share all the code from my Best Practices – Creating an OData Service using WCF Data Services session at TechED.
Note: you can find a recording of that session here.
So here goes, essentially this is what I did:
Added a query interceptor to only allow users to see just the own orders:
[QueryInterceptor("Orders")] public Expression<Func<Order, bool>> OrdersFilter() { var user = HttpContext.Current.User.Identity.Name; if (string.IsNullOrEmpty(user)) return (Order o) => false; else if (user== "Administrator") return (Order o) => true; else return (Order o) => o.Username == user; }
<system.web.extensions> <scripting> <webServices> <authenticationService enabled="true" requireSSL="false"/> </webServices> </scripting> </system.web.extensions>
You can download the finally copy of the Music Service code if you want.
Enjoy and good luck.