Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need to Set the Session Variable

Posted on 2013-06-01
5
Medium Priority
?
586 Views
Last Modified: 2013-06-03
I need to store session information.

private void LogError(SqlConnection pconStockSelect)
        // Collects error information and saves it in the errors table.
        {
            strErrMessage = Session["Message"].ToString();

error: the Session variable is null.

How do I set the Session variable?

Thanks,
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 22

Expert Comment

by:Om Prakash
ID: 39213045
if ( Session["Message"] != null )
{
  string errmsg  = Session["Message"];
  // do other stuff
}
0
 
LVL 58

Expert Comment

by:Gary
ID: 39213069
You set a session like so
Session["session_name"] = "Text";

But that's got nothing to do with the code you posted
0
 

Author Comment

by:Dovberman
ID: 39213113
The ShowError page is opened when an exception is triggered.

I have try/catch blocks in several places.

The exception that opened this page is not handled.

I need to see a stack trace to find out where the exception occurred.

The exception is somewhere in this code that attempts to set up a site map.

The bug was removed when I removed this code from the master page:

    <tr id="rowSiteMap">
                <td colspan="2" style="width: auto; height: 24px;
                    font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; font-style: normal;
                    font-variant: normal; border: thin solid #0000FF;
                    color: #0000FF; background-color: #FFFFCC; text-align: left;">
                   
                    <asp:SiteMapPath ID="SiteMapPath1" runat="server" Width="65%" Font-Size="12pt">
             
                      <PathSeparatorTemplate>
                          <asp:Image ID="Image1" ImageUrl="~/Images/arrowright.gif" runat="server" />
                      </PathSeparatorTemplate>
                     
                      <RootNodeTemplate>
   <b style="font-family: Arial, Gill Sans; font-size: 14px; " >You are here </b>
                      </RootNodeTemplate>
             
                      <CurrentNodeTemplate>
                        <%# Eval("title") %>
<br /><b style="font-family: Arial, Gill Sans; font-size: 12px"></b>&nbsp;
<%# Eval("description") %>
                      </CurrentNodeTemplate>
             
                    </asp:SiteMapPath>
</td>
</tr>


Could you recommend a document that shows how to set up the site map?

I would also like to know how I can get exception information when I have no idea where the exception came from.

This is the web.config statement that directs exceptions to the exception details page.

<customErrors mode="On" defaultRedirect="~/ErrorHandling/ShowError.aspx">
    </customErrors>

Thanks,

Thanks,
0
 
LVL 10

Accepted Solution

by:
Monica P earned 1200 total points
ID: 39215956
Initially check that  Session["Message"] is not nothing  or  is not empty

if Not Isnothing( Session("Message")) then
End if

Without checking the Session values ., converting it to a string may be cause for the error message

If it suits your requirement ., just make a setting before making conversion into string
0
 

Author Closing Comment

by:Dovberman
ID: 39216418
Thank you.
0

Featured Post

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!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

618 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