Determine if WebApp was Launched from Visual Studio

T

Tyrant Mikey

Hi all.

I've got some code I've placed in my global.asax file that registers a
trace listener. The listener actually makes Debug.Assert statements
that fail break into the debugger, which is quite handy for me.
However, if the user didn't launch the application from Visual Studio,
the listener wreaks havoc with their browser (lots of nefarious
JavaScript errors).

The code I've included in global.asax looks like this:

----------------------------------------------------------------------
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)

Debug.Listeners.Add(New AspNetAssertListener)

End Sub
----------------------------------------------------------------------

Now, what I'd LIKE to do is add the listener only IF the web
application was launched from the IDE. Something like this:

----------------------------------------------------------------------
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)

If InIDE() Then
Debug.Listeners.Add(New AspNetAssertListener)
End If

End Sub
----------------------------------------------------------------------

Does anyone know if there's a way to determine whether or not the
application has been launched from the IDE?

Thanks!
 
H

Hans Kesting

Tyrant said:
Hi all.

I've got some code I've placed in my global.asax file that registers a
trace listener. The listener actually makes Debug.Assert statements
that fail break into the debugger, which is quite handy for me.
However, if the user didn't launch the application from Visual Studio,
the listener wreaks havoc with their browser (lots of nefarious
JavaScript errors).

The code I've included in global.asax looks like this:

----------------------------------------------------------------------
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)

Debug.Listeners.Add(New AspNetAssertListener)

End Sub
----------------------------------------------------------------------

Now, what I'd LIKE to do is add the listener only IF the web
application was launched from the IDE. Something like this:

----------------------------------------------------------------------
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)

If InIDE() Then
Debug.Listeners.Add(New AspNetAssertListener)
End If

End Sub
----------------------------------------------------------------------

Does anyone know if there's a way to determine whether or not the
application has been launched from the IDE?

Thanks!

One thing you could try to do is wrap the code in
#if DEBUG
#endif
commands. If you recompile in "Release" mode (as for a "live" site)
this code is not included.

Hans Kesting
 
T

Tyrant Mikey

I considered that, but the problem is that there's plenty of code in
#IF DEBUG...#ENDIF blocks elsewhere in the program that I *want* to
execute in the test environment.

I suppose I could define another constant, and use 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

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,369
Latest member
Carmen32T6

Latest Threads

Top