Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Getting error while setting session value

Reply
Thread Tools

Getting error while setting session value

 
 
sony.m.2007@googlemail.com
Guest
Posts: n/a
 
      06-12-2008
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
 
Reply With Quote
 
 
 
 
Manish
Guest
Posts: n/a
 
      06-12-2008

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
"(E-Mail Removed)" 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
>

 
Reply With Quote
 
 
 
 
sony.m.2007@googlemail.com
Guest
Posts: n/a
 
      06-12-2008
On Jun 12, 12:11 pm, Manish <(E-Mail Removed)> wrote:
> 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
>
> "(E-Mail Removed)" 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting error while getting Google plus posts George Java 4 06-28-2012 07:53 PM
problem while setting srcollLeft a value Madni Javascript 0 04-05-2006 11:46 AM
How to avoid getting BGP routes while getting a router's routing table ncosta@net.ipl.pt Cisco 2 01-25-2006 11:50 AM
Help while error "Error while trying to run project:" David ASP .Net 1 07-19-2004 08:41 PM
Got error msg while Debugging : Error while trying to run project: ... ^CrazyCoder^ ASP .Net 3 09-15-2003 09:40 AM



Advertisments