Name
TargetSite
Synopsis
MethodBase = HttpException.TargetSite
Returns
a MethodBase instance (the MethodBase class
resides in the System.Reflection namespace) representing the method
from which the exception was thrown. You can query the properties of
MethodBase, such as the Name property, which
returns the name of the method. You can also call ToString on the
instance to return information about the method in a usable format.
Parameters
-
MethodBase An instance of the
MethodBaseclass representing the method from which the exception was thrown.
Example
The code example causes an exception by attempting to set a Session
value on a page for which the EnableSessionState
attribute of the @
Page
directive has been set to False. The example code
then displays the resulting error message and uses the Name property
of the MethodBase instance returned by the TargetSite property to
display the name of the method from which the exception was thrown:
<%@ Page Language="vb" EnableSessionState="false" %>
...
Sub Page_Load( )
Try
Session("foo") = "Foo"
Catch HttpEx As HttpException
Message.Text = "ERROR:<br/>"
Message.Text &= "Message: " & HttpEx.Message & "<br/>"
Message.Text &= "Target Site: " & HttpEx.TargetSite.Name & "<br/>"
End Try
End SubNotes
In the example, we access the Name property of the MethodBase
instance directly, without creating a separate local variable of type
MethodBase. This direct access saves us the trouble of either adding
an @
Import statement to import the System.Reflection ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access