How do I get the function and page name?

Last post 12-13-2005 10:57 AM by IKoradia. 5 replies.

Sort Posts:

  • How do I get the function and page name?

    12-12-2005, 1:47 PM
    • Member
      131 point Member
    • raynkel
    • Member since 02-02-2004, 10:59 AM
    • Posts 34
    How do I programatically get the page name and function My code is running?

    I use this code:
      Catch ex As Exception

          Dim cookie As HttpCookie = New HttpCookie("Error")
          cookie.Value = ex.Message
          Response.Cookies.Add(cookie)

          Dim ThisPage As String = "SavingsTracker.aspx"
          Dim FunctionName As String = "GetUsersAgency"
          Dim URLString As String = "ErrorPopup.aspx?Page=" & ThisPage & "&Function=" & FunctionName
          Response.Redirect(URLString)

    To capture errors during testing. I use it quite a few times and having to declare the function name and Page is tedious.
    I write the error to a cookie because some times it is two lines and query strings no likey.

    Can these values be gotten? Also what about line number? That would be excellant!!



  • Re: How do I get the function and page name?

    12-12-2005, 2:30 PM
    • Contributor
      3,692 point Contributor
    • eramseur
    • Member since 10-09-2004, 12:36 AM
    • Washington DC
    • Posts 752
    Check out this page : http://west-wind.com/weblog/posts/269.aspx

    There is more if you just do a " get current page asp.net" search.

  • Re: How do I get the function and page name?

    12-12-2005, 4:21 PM
    • Member
      131 point Member
    • raynkel
    • Member since 02-02-2004, 10:59 AM
    • Posts 34

    That has information about getting the Web page name and such. Part of what I need. Still need to get the actual function I am in

    This seems to work.

    Dim d As String = Mid(ex.StackTrace.ToString, ex.StackTrace.LastIndexOf(vbNewLine) + 3, ex.StackTrace.Length)

    Dim c As String = Mid(d, d.IndexOf(".") + 2, d.Length)

    Dim LineNum As Integer = Mid(ex.StackTrace.ToString, ex.StackTrace.LastIndexOf(":") + 6, ex.StackTrace.Length) - 1

    Dim FunctionName As String = Mid(c, c.IndexOf(".") + 2, c.IndexOf("()") - 7)

     

    Am hoping for a more direct route.

     

    Thanks

  • Re: How do I get the function and page name?

    12-12-2005, 5:13 PM
    • Member
      20 point Member
    • IKoradia
    • Member since 12-07-2005, 9:54 AM
    • Posts 4
    For the function name, you could use:

    Dim mb As System.Reflection.MethodBase = System.Reflection.MethodBase.GetCurrentMethod()
    Dim FunctionName As String = mb.Name

    hope that helps,
    Imran.

  • Re: How do I get the function and page name?

    12-13-2005, 9:10 AM
    • Member
      131 point Member
    • raynkel
    • Member since 02-02-2004, 10:59 AM
    • Posts 34

    Great thanks, anyone know how to get the line number?

     

    Thanks

  • Re: How do I get the function and page name?

    12-13-2005, 10:57 AM
    • Member
      20 point Member
    • IKoradia
    • Member since 12-07-2005, 9:54 AM
    • Posts 4
    I'm not sure this will get you the line number you are looking for but here's a way:

    Dim st As New StackTrace(ex)   'create a stacktrace from your exception
    st.GetFrame(0).GetFileLineNumber() 'get the line number

    Also, I don't think this would work in release mode since the line number (among other information) is retrieved from the debug symbols that are created only when in debug mode. Anyway, you can give it a shot.

    hope that helps,
    Imran.
Page 1 of 1 (6 items)