Can't save the value in HttpContext.Current.Session state

Hello,

I have a class file (class1.cs) and I'm trying to put the variable in the HttpContext.Current.Session so I can access it in another class file (class2.cs) but get an error: "Object reference not set to an instance of an object".  Does anyone knows why and how do I solve it?  Thanks in advance.

class1.cs 

HttpContext
.Current.Session.Add("ReportName", ReportName);    //Error: Object reference not set to an instance of an object.


 

0
boston_ma
1/2/2009 4:27:37 PM
asp.net.state-management 8807 articles. 0 followers. Follow

6 Replies
1709 Views

Similar Articles

[PageSpeed] 22

It seems that the Httpcontext is not avalible from where you are trying to access it. Can you explain further more about your senario.

 


Mark "answer" if my post helped you find the answer.
"And say: My Lord increase me in knowledge."

B/R
Huthaifa Afanah
0
istofix
1/2/2009 6:26:50 PM

So, can you see if the HttpContext object is null. Where are you calling this class from. Are you doing anything special like executing this code on a separate thread.

Also, is the call this class part of the regular asp.net event handling call stack, like calling from page_load, or Page_PreRender


Kumar Reddi
0
Kumar
1/2/2009 6:32:12 PM

istofix:

It seems that the Httpcontext is not avalible from where you are trying to access it. Can you explain further more about your senario.

I have an IHttpHandler class along with 2 other cs class files.  First, it's going to execute the code in IHttpHandler class, then call the class1.cs and use one of the function in there.  In this function, I'm going to use the information in class2.cs but I need to pass a lot of data to this class2.cs.  So instead of passing the variable one by one, I want to save the variable/data in the session state and retrieve the data out of the session state in class2.cs, but I'm having trouble of saving the data in the "HttpContext.Current.Session.Add()" in class file.  Is there a better way to save the data in the Session state in the class file?

0
boston_ma
1/2/2009 6:49:40 PM

Kumar Reddi:

So, can you see if the HttpContext object is null.

The HttpContext.Current.Session is null

Where are you calling this class from.

I'm calling this code in the class1.cs file

Are you doing anything special like executing this code on a separate thread.

No, basically trying to save the data in the current session and retrieve it in other class 2 file

Also, is the call this class part of the regular asp.net event handling call stack, like calling from page_load, or Page_PreRender

No, this is the http handler, no web form

0
boston_ma
1/2/2009 6:57:50 PM

 I am reading else where on the web that you would have to implement one of the following interfaces also along with IHttpHandler, if you

IRequiresSessionState 

IReadOnlySessionState

Here is a blog post that talks about it

http://weblogs.asp.net/ashicmahtab/archive/2008/09/18/how-to-use-session-values-in-an-httphandler.aspx


Kumar Reddi
0
Kumar
1/2/2009 7:10:39 PM

Thankyou very much for the information

0
boston_ma
1/2/2009 7:34:42 PM
Reply:

Similar Artilces:

Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'
 Hi,We are trying to implement Network loading for our asp.net (1.1) application for which we are storing the session in State Server.Following is the error is thrown while page is rendered when ever is a DTO is stored in to SEssion in any of the page.Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer' Following the code I written for DTO (C# Asp.net 1.1).     using System;    using System.Runtime.Serializa...

After a looong night managed to change Session mode from inProc to SQLServer but still can't get the session variables to be saved
Hi,  I ran my Shopping Cart project and somehow everything worked fine(while in inProc), session variables were saved fine. I made some changes to my project and since then keep getting null session variables, no matter what I do. It took me the whole night to figure out how to turn to SQLServer mode,  marked custom classes as 'Serializable' with [Serializable] before the class definition but everything's in vain. Getting the same damned 'nulls' instead of the saved objects. private void Page_Load(object sender, System.EventArgs e)         {...

can't load assembly for session state
I'm trying to create a session state where I can store a user's id and use it on each page they access during a session. I included the following in my web config file. <add name="sessionState" type="System.Web.SessionState.SessionStateModule, Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" /> When I try to open a web page in my app I get the following error: File or assembly name Version=1.0.3300.0, or one of its dependencies, was not found. and the following trace information. Can anyone solve this problem for me. Thanks === ...

Session and View state values are changed: mixed with simultaneous users' session and viewstate values.
I have developed one aspx page(c#) that includes 7pages of the input form: each page is surrounded with panel control. It will be hidden or shown depending on which page the user wants to go. There are several update panels that contain gridview controls on the page. The source of the gridview is session value (arrayList). Whenever the page is postbacked by clicking previous and next buttons to show a certain page and hide other page panels, or adding new list data into the arrayList of the session value ( the value is retrieved on the pertaining gridview), the session and server control val...

I can't get no cache, I can't get no cache. 'Cause I try and I try and I try and, I can't get no, I can't get no cache.
I have fiddled out for days tinkering with the setting in about:config trying to get FireFox 12 to use the disk cache. I have NOT found the trick. This One Trick Pony ain't doing it like it used to up until recently. Pray tell anyone, What information can I share that will point a knowledgeable person to aid me in getting FF to disk.cache? I have also tried restarting FF with add-ons disabled, (There were NOT too many to do this to, so it was quick and easy) Here is my stab at trying to convey the information that MIGHT govern matters Using about:cache Informatio...

Re: I can't get no cache, I can't get no cache. ' Cause I try and I try and I try and, I can't get no, I can't get no cache.
<div>please com e see me about htis<br /> <br /> ------- Original Message f= rom the Global Relay Archive -------<br /> From: Hp &lt;ferd@farkel.net&gt;= <br /> To: "support-firefox@lists.mozilla.org" &lt;support-firefox@lists.mo= zilla.org&gt;<br /> Sent: Sun, 27 May 2012 18:30:18 -0700<br /> Subject: I = can't get no cache, I can't get no cache. 'Cause I try and I try and I try = and, I can't get no, I can't get no cache.<br /> <br /></div> <pre class=3D"gr-maex-body-pre&qu...

Can't retain Session State when accessed from public browser
I'm exhausted trying to straighten this server out.  Any help would greatly appreciated.  I'm a one man show for my company which is tough.  The server is a Windows 2003 Small Business server with IIS6.  My code works fine in dev and also when viewed from the browser on the server machine but when accessed from a publc browser address(www.MyCompany.com) it doesn't retain Session state.  Drawing data from SQL works fine. For example, this simple code will not work. Session state is lost on postback. Protected Sub Page_Load(ByVal sender As Object, ByVal e As Sy...

Can't Manage State of controls dynamically added to page
I'm developing a project for a company of engineers here i need to load a page dynamically with user controls that i had created. So the main idea is: we are talking about houses and an element basically is a room, a living room, a bathroom,etc and a sub element can be the door, wall, footer and closet of the room, so here we have 1 element with 3 sub elements. Now inside each sub element i have anomalies that should be analised to check if it's everything ok and its here that the user control that i create comes in. I create a user control that shows me the title of the sub element ...

2010: Can't register - can't download the software - can't register until I have the software
I have active maintenance on Rad Studio: From: Vicky Rassmisaengthong [mailto:Vicky.Rassmisaengthong@EMBARCADERO.COM] Sent: Wednesday, February 25, 2009 1:58 PM To: rgrossman Cc: amer.supportadmin@codegear.com; Ashley Cosentino Subject: Software Assurance Support for Tech III Inc PO# Credit Card Dear Embarcadero Technologies Support Customer, Welcome! You have been registered as the primary contact on support account number AM####### Herewith we confirm your Embarcadero Technologies support agreement covering: Qty 1 RAD Studio Enterprise Named User licens...

'Can't save web pages, Ctrl+S. 'Can save same pages from I.E
Name: Del Dyreson Email: drdyreson_at_earthlink.net Product: Firefox Summary: 'Can't save web pages, Ctrl+S. 'Can save same pages from I.E Comments: 'Can't save web pages, Ctrl+S. 'Can save same pages from I.E. I'm running Win2000Pro, Ver 5.0 (Build 2195, Service Pack 4). Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4 ...

Can't save and/or can't read mail
This is a multi-part message in MIME format. --------------060900090409060907050501 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I created a few new accounts in SM to read administrative addresses. When I went back to read my main mailbox I got a message something like "can't save mail, do you have permissions" and yes, I do. I note that the permissions in various accounts are not all the same, some directories are 755, some are 700. Same for Mail files. In any case I have permissions, so what is this really saying. (...

Can't update my database because I can't retrieve the value from radiobuttonlist
Hello I am a beginner in ASP.NET and I am now developing a poll application but I had a problem and I could not solve it. The problem is that I could not use an update query because my SQL statement cannot retrieve the value from radiobuttonlist . I am now stack in this point and I could not complete my application. I could not  attach the website because I am not allowed. I don't know why. Note : the error message is  No value given for one or more required parameters.   My CODE : Conn.Open() Cmd3 = New OleDbCommand("Update PollAnswer Set PollCount = PollCount + 1 Where...

Win 2003 web server on LAN with iis 6.0 and .net 2.0 doesn't return HttpContext.Current.User.Identity.Name value
Hi. I'm accessing a Win 2003 web server on LAN with iis 6.0 and .net 2.0 that doesn't reuturn HttpContext.Current.User.Identity.Name value in asp.net 2.0 c# although I am logged on to the network domain.  Any advice on why and how to rectify this? The web.config file has authentication mode="Windows" set.  Thanks for any help!...

I can't get current default value from DataTableReader, How can I do ?
I would like to check current structure especially "default value"However after I use DataTableReader to get structural value from any table , there was only null value   How can I get structural value from real table in database with others method ????  Please help me ?  Hi, I'm not clear what you want. But if you want to navigate the contents of a DataTableReader ,try the following articles. http://msdn2.microsoft.com/en-us/library/z071789y(VS.80).aspx Thanks.Michael Jin.Microsoft Online Community SupportPlease remember to mark the...

Web resources about - Can't save the value in HttpContext.Current.Session state - asp.net.state-management

User Will - Stack Overflow
current community chat blog Stack Overflow Meta Stack Overflow Stack Overflow Careers your communities Sign up or log in to customize your list. ...

OPAC Discovery
Message:The file '/H92010/OPAC/Details/OPAC/Login.aspx' does not exist.Source:http://206.187.18.64/H92010/OPAC/Details/OPAC/Login.aspxStack Trace: ...

Tigraine
Daniel Hoelbling talks about programming Home Articles About me Articles Over the years I accumulated a number of (at least sometimes) useful ...

Blog archive - Splinter Software
Chris Hulbert, Splinter Software, is a freelance iOS developer based in Sydney, Australia.

Unobtrusive AJAX with ASP.NET MVC
... class ReturnJsonForAjaxRequests : ActionFilterAttribute { public bool FollowRedirects = true; public static Func new HttpRequestWrapper(Htt ...

Asp.net MVC增加全局异常捕获500、404错误
/// /// 错误日志(Controller发生异常时会执行这里) /// public class AppHandleErrorAttribute : HandleErrorAttribute { /// /// 异常 /// /// public override void ...

ARCC :: About Ares Capital :: Product Offerings Session state has created a session id, but cannot save ...
... but cannot save it because the response was already flushed by the application.] System.Web.SessionState.SessionIDManager.SaveSessionID(HttpContext ...

Job Search Canada - Employment Opportunities Site - Find & Post Jobs Online
Find and post jobs online - search for jobs across Canada, read the latest employment news articles, get career tips and advice at Canada's top ...

系统异常
... Boolean throwIfNotFound, Boolean ensureIsUpToDate) at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context ...

Web Optimization in Visual Studio 2012 RC
... the site, those files will be bundled and minified. By default, this property looks at the IsDebuggingEnabled property of the current HttpContext, ...

Resources last updated: 2/7/2016 10:53:50 PM