Thanks Kevin,
That's exactly what I needed to confirm.
It's good to know that it's a reliable to check
System.Web.HttpContext.Current to detect the environment.
In ASP.NET environment, I found out the
System.Threading.Thread.CurrentPrincipal.Identity. Name returns the
Authenticated user and the
System.Security.Principal.WindowsIdentity.GetCurre nt().Name returns the
identity of my web service account name.
In Windows Service environment, the
System.Threading.Thread.CurrentPrincipal.Identity. Name return System.Empty
and System.Security.Principal.WindowsIdentity.GetCurre nt().Name returns the
service account Name.
Could you please confirm what account name can be retrieved more reliably in
all cases in your suggestion "IMO, it's better to use
System.Threading.Thread.CurrentPrincipal.Identity. Name to get the account
name. Since it gets the same thing as WindowsIdentity.GetCurrent().Name,
but it's more reliable under all circumstances."
Thanks very much!
John
reliable method to check for the environment
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:Y1***************@cpmsftngxa10.phx.gbl... Hi John,
First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know how to check if the
component is called under ASP.NET or Windows service. If there is any
misunderstanding, please feel free to let me know.
Based on my experience, check for System.Web.HttpContext.Current is a
reliable method to check for the environment. IMO, it's better to use
System.Threading.Thread.CurrentPrincipal.Identity. Name to get the account
name. Since it gets the same thing as WindowsIdentity.GetCurrent().Name,
but it's more reliable under all circumstances.
HTH.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."