tags:

views:

101

answers:

2

How can I, from within a method, verify that it executes inside a remoting context? I've got a basic Client -> NT-Service setup where the service executes as a specific user. This user has access to a SQL Server.

I am looking for a solution that would make it easier to catch problems that occur when the remoting configuration is missing or bad (a method that wasn't specified, etc). I would like to be able to fail with a better error message ("This method requires a remoting context to work properly.") instead of failing with login errors. It's even more tricky when the original user has readonly access to the database and the error isn't thrown until data is written.

A: 

I like using the MS enterprise Library for debugging purposes, you can try using the logging and the exception handling blocks to handle the error.

Nidhi
I am not looking for ways to handle the error, but to detect if I am inside a remoting context.
Simon Svensson
+1  A: 

Well, you could use use the stacktrace class in System.Diagnostics to check where the method call is coming from. :)

Simon Söderman
Note that walking the stack isn't without performance implications.
Mark