I am familiar with impersonating an account in .net by using:
dim myIdentity as WindowsIdentity = someIdentity
using ctx as WindowsImpersonationContext = myIdentity.Impersonate()
doStuff()
end using
Is it possible to define a .net attribute so that I could write something like:
< runAsUser(someIdentity) > public sub doStuff()
and then have the .net framework always impersonate when running the method doStuff()
?
Update Okay, I'm told that this may be impossible because arguments to an attribute constructor must be constants which would rule out passing in the user's identity.
Let me ask the question a little bit differently:
Suppose there were a function getUserWindowsIdentity()
that returns an identity associated with the logged in user.
Could I then use < runAsLoggedInUser) > public sub doStuff() >
to make the framework always impersonate the user id returned by getUserWindowsIdentity
when running the doStuff()
method?