Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends

I am working on a big project. A session variable Session["key"] is used around 200 times.
Meanwhile its value is updated also.


I want to know how i can find where it was first used and initialized.
can i access it with client side script.....


Please reply if anyone know about....




Thanks In Advance
Posted
Comments
Thanks7872 10-Jul-14 8:52am    
If you don't know how your BIG project is working, it makes no sense to work with it at all.
[no name] 10-Jul-14 8:57am    
Is there some reason you can't search your solution for "Session["key"] ="?
dhiman.rohit9 10-Jul-14 9:35am    
no i know the process of project.
but the issue is i am searching for Session["key"] , and i am getting for the same.
but i have this key many times. i am not finding where it was first initialize with value..

1 solution

You can access session value using jquery as shown below

Code behind file:

C#
protected void Page_Load(object sender, EventArgs e)
        {

            //You have to set  this value in master page if you have if not then  in Content page at pageload  
            setSessionToHiddenValue();
        }

        //Method for set session value to  hidden  field for access this value in jquery 
        protected void setSessionToHiddenValue()
        {
            Session.Add("fname", "Arvind");
            Session.Add("lname", "Mepani");
            hdnFname.Value = Convert.ToString(Session["fname"]);
            hdnLname.Value = Convert.ToString(Session["lname"]);

        }



and Aspx view page is below

XML
<head runat="server">
    <title>Access Session in jquery</title>
    <script src="Scripts/jquery-1.9.1.js"></script>
    <script>

        $(function () {
            console.log("Document is ready");
            //First way to access session
            console.log("Session value from Session Object");

            console.log("Firstname:" + '<%=Session["fname"] %>');
            console.log("Lastname:" + '<%=Session["lname"] %>');
            //second way is to fetch value from hiddenvalue
            console.log("Session value from hidden value");
            console.log("Firstname:" + '<%=hdnFname.Value %>');
            console.log("Lastname:" + '<%=hdnLname.Value %>');


        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <asp:HiddenField ID="hdnFname" runat="server" />
                <asp:HiddenField ID="hdnLname" runat="server" />
        <div>
        </div>
    </form>
</body>
 
Share this answer
 
v2
Comments
CHill60 10-Jul-14 9:14am    
I've gone through this but I can't work out how this tells me when a session variable was first used. What am I missing?
arvind mepani 10-Jul-14 9:20am    
There is no way to find when and where your session value is first initialized but one thing you definitely do like create Dictionary object or list object of Session value where ever you set session add this value to list and then save this list to session.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900