Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Session variables in global.asax

Posted on 2006-06-02
8
Medium Priority
?
5,063 Views
Last Modified: 2010-11-04
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
Comment
Question by:NBAIS
  • 4
  • 3
8 Comments
 
LVL 10

Expert Comment

by:eyal_mt
ID: 16817906
Try:
 System.Web.HttpContext.Current.Session.Item("SSN")....
0
 
LVL 4

Expert Comment

by:indu_mk
ID: 16817925
Try User.Identity
0
 
LVL 4

Expert Comment

by:indu_mk
ID: 16817938
Try User.Identity.Name
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:NBAIS
ID: 16817974
How does User.Identity.Name reference the session variable that I need it to send me?
0
 
LVL 4

Expert Comment

by:indu_mk
ID: 16817994
>> 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
 

Author Comment

by:NBAIS
ID: 16818045
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
 
LVL 4

Accepted Solution

by:
indu_mk earned 2000 total points
ID: 16818136
How abt  sender.Context.Session("SSN")?
0
 

Author Comment

by:NBAIS
ID: 16818190
Any reference I make to the session kills the process.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question