Hi Yatin,
Yes. The approach mentioned above will work correctly but I was looking for the solution in code so that it will not introduce new field addition on the entity. And finally I got an solution for this.
This is how it works:
Though 'CallerOrigin' property is deprecated in CRM 2011, we can check to see the origin of the plugin (which doesn't actually work on 'Online' deployments) by using this code:
context.GetType().GetProperty("CallerOrigin").GetValue(context, null).GetType().Name
which will return values like:
ApplicationOrigin / AsyncServiceOrigin / WebServiceApiOrigin
So, this way, it solved the issue I was facing.
Hope this helps!
Thanks,
Abhi