• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5068
  • Last Modified:

Session variables in global.asax

Currently we are setting up a customs error page in our site.  When an error occurs, the user is directed to the custom error page and an email is fired off from global.asax as to what occured with the compiler throug the following code:  

Protected Sub Application_Error(ByVal Sender as Object, ByVal e as EventArgs)
 
    Dim ErrorDescription As Exception = Server.GetLastError
    Dim url As String
    Dim body As String

               
    If Not (ErrorDescription Is Nothing) Then
       
        ErrorDescription = ErrorDescription.InnerException
     
        'Build My message body
       
            body = "<b>Error Message:</b><br>" & ErrorDescription.Message & _
                     "<br><br><b>Error Source:</b><br>" & ErrorDescription.Source & _
                    "<br><br><b>Error Type:</b><br>" & ErrorDescription.GetType.ToString() & _
                    "<br><br><b>Target Site:</b><br>" & ErrorDescription.TargetSite.ToString() & _
                    "<br><br><b>Stack:</b><br>" & ErrorDescription.StackTrace & _
                    "<br><br>"
               
             
        url = Request.Url.AbsoluteUri
        Dim mailMessage As New MailMessage
        mailMessage.From = "is@domain.com"
        mailMessage.To = "is@domain.com"
        mailMessage.Subject = "ATTENTION: Web Site Error"
        mailMessage.BodyFormat = MailFormat.Html
        mailMessage.Body = body
        mailMessage.Body += url
        System.Web.Mail.SmtpMail.SmtpServer = "SMTPServer"
        System.Web.Mail.SmtpMail.Send(mailMessage)
       
    End If
   
End Sub

While the user is logged in the site has the username as a session variable.  How do I get the global.asax file to pass the username to me through this email?
I've added Session.Item("SSN").ToString and all that does is break and make it so it doesn't send an email at all.  Any ideas? Thanks in advance for your assistance.
0
NBAIS
Asked:
NBAIS
  • 4
  • 3
1 Solution
 
eyal_mtCommented:
Try:
 System.Web.HttpContext.Current.Session.Item("SSN")....
0
 
indu_mkCommented:
Try User.Identity
0
 
indu_mkCommented:
Try User.Identity.Name
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
NBAISAuthor Commented:
How does User.Identity.Name reference the session variable that I need it to send me?
0
 
indu_mkCommented:
>> How do I get the global.asax file to pass the username to me through this email?

User.Identity.Name will give the logged in username. Thats why I pointed out that.
0
 
NBAISAuthor Commented:
System.Web.HttpContext.Current.Session.Item("SSN") breaks it so that it doesn't send an error and User.Identity.Name sends an empty string because there isn't really a user other than a variable stored in Session("SSN").
0
 
indu_mkCommented:
How abt  sender.Context.Session("SSN")?
0
 
NBAISAuthor Commented:
Any reference I make to the session kills the process.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now