473,416 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Getting error while setting session value

Hi,
When i try to set a value for a session variable I'm getting a object
refence not set error

I tried two methods as below
HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);
HttpContext.Current.Session["AppStartTime"] = DateTime.Now;

For the above two methods I'm getting error as
"Object reference not set to an instance of an object."
Kindly help me out.

Thanks,
Sony
Jun 27 '08 #1
2 2771

Hi Sony,

I tried the code and it works fine.

protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Session["AppStartTime"] = DateTime.Now;
Response.Write(Session["AppStartTime"].ToString());
}

Regards,
Manish
www.componentone.com
"so*********@googlemail.com" wrote:
Hi,
When i try to set a value for a session variable I'm getting a object
refence not set error

I tried two methods as below
HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);
HttpContext.Current.Session["AppStartTime"] = DateTime.Now;

For the above two methods I'm getting error as
"Object reference not set to an instance of an object."
Kindly help me out.

Thanks,
Sony
Jun 27 '08 #2
On Jun 12, 12:11 pm, Manish <Man...@discussions.microsoft.comwrote:
Hi Sony,

I tried the code and it works fine.

protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Session["AppStartTime"] = DateTime.Now;
Response.Write(Session["AppStartTime"].ToString());
}

Regards,
Manishwww.componentone.com

"sony.m.2...@googlemail.com" wrote:
Hi,
When i try to set a value for a session variable I'm getting a object
refence not set error
I tried two methods as below
HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);
HttpContext.Current.Session["AppStartTime"] = DateTime.Now;
For the above two methods I'm getting error as
"Object reference not set to an instance of an object."
Kindly help me out.
Thanks,
Sony
Hi,
My class implements IHttpModule
and I'm assigning the session value at onbeginrequest method

public class TestHTTPModule : IHttpModule
{
public void Init(HttpApplication application)
{
application.BeginRequest +=
(new EventHandler(this.Application_BeginRequest));
}
private void Application_BeginRequest(Object source,
EventArgs e)
{
HttpContext.Current.Session.Add("AppStartTime",
DateTime.Now);
HttpContext.Current.Session["AppStartTime"] = DateTime.Now;
}
}

If u try like above you will get the error message.
How to solve this?

Thanks,
Sony
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
4
by: Bryan Tang | last post by:
I built an ASP to search the content in index server. It is ok if search in English. Whenever I search in Chinese, I will got the following error message, CreateRecordset ?u?~ '80004005' ...
10
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through...
0
by: Adam Getchell | last post by:
I'm attempting to write a custom Authentication module using http://www.15seconds.com/Issue/020417.htm I looked at http://support.microsoft.com/default.aspx?scid=kb;EN-US;307996, but it doesn't...
1
by: Ramanfromoz | last post by:
Hi, Developing a new we application. Everything okay on my local WIN XP PROFESSIONAL, IIS 5.0 running locally. The website is running smoothly. Now, the same code I am copying over to a...
15
by: jkmambo | last post by:
Session data is getting lost in PHP version 4.4.1 which used to work in version 4.3.3 The code is similar to the one below Assume the file is called count.php which requires a parameter...
2
by: ronchese | last post by:
I'm noticing this since I started developing a website project: my session variables are getting empty! I did a real easy test, and I checked my session variable is getting empty!! What is...
1
by: spitapps | last post by:
I want to have sessions on my website, this is my web.config file: <configuration> <appSettings/> <connectionStrings/> <system.web> <sessionState mode="InProc" cookieless="UseCookies"...
2
by: preeti13 | last post by:
Hi guys i am here with my another probelm please help me.trying insert the value into the data base but getting the null value error .I am getting thsi error Cannot insert the value NULL into...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.