Is the current environment ASP.NET?

H

Harjit S. Batra

How can a function tell if it has been called from a ASPX page or ASMX web
service versus being called from a console or windows app? I need to extend
the EventLog class to write events and need to know the name of the app or
the name of the page or the name of the service calling the WriteEvent
method, so that the event source can be correctly identified? I cannot even
compile code as a DLL with the HttpContext class as part of the code! Any
help will be appreciated.

Harjit
 
C

Chris Marchal[MSFT]

You may be able to get the information you need from the current call
stack. This can be examined by using the StackTrace class in the
System.Diagnostics namspace. This class will allow you to look at all the
calls (termed frames) that lead to the current executing function. From
the stack frame you will be able to get the method name being called and
the name of the assembly (hence application, web service etc.) from the
declaring type.

Regards,

Chris Marchal
Microsoft UK Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

Dino Chiesa [Microsoft]

the way I do it is

if (System.Web.HttpContext.Current!=null)
// I am running within ASP.NET

I don't understand what you mean by "I cannot even compile code as a DLL
with the HttpContext class as part of the code...."

-Dino

ps: please do not cross post. No need for that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top