Hi,
First way that comes to my mind is to check if web context exists. That
would be something like:
If Not System.Web.HttpContext.Current Is Nothing Then
...
End If
Downside is that this requires reference to System.Web assembly.
Another would be checking what Environment.UserName returns, though this of
course ain't 100% reliable on cases when system is configured from defaults.
with default settings this returns ASPNET in Win2k , and probably
NETWORK_SERVICE with Win2k3 Server, but of course if process is configured
for another user, this isn't reliable. With WinForm this would return the
user that started the application.
Third could be as was said, checking that in which process app is running:
Dim proc As System.Diagnostics.Process =
System.Diagnostics.Process.GetCurrentProcess()
proc.ProcessName would return name of the process the app runs under. With
ASP.NEt on Win2k machine it would be aspnet_wp. On Win2k3 it would be the
same IIS's process by default.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist