State Management :: HttpContext.current.session Is Null In App_code/.cs File

May 20, 2010

1. SetSession.aspx page sets value for a session variable and redirects to default.aspx page using Response.redirect() code.

2. Default.aspx page tries to create an object of class in app_codecommon.cs file.

3. In app_codeCommon.cs file, I am trying to access the session variable set in step1 using HttpContext.Current.Session object.

but step 3 gives error that object reference not set to an instance. as HttpContext.Current.Session is null.

I surf abt it on net, and seems to be problem with asp.net framework.

View 1 Replies


Similar Messages:

State Management :: Users Getting Logged Out Because HttpContext.Current Is Null?

Aug 19, 2010

We've got a fairly large, complex web application that uses Forms Authentication to authenticate users. Throughout the application we store and retrieve information about users in the Session object, and in some cases in cookies. In a couple places we check for the existence of the context, and if it's null we send the user back to the login page to re-establish the session. Just a quick run-down of this web app: C#, .NET 3.5, IIS 6, ASP.NET State Service to manage sessionAs for the session timer, we use our own home-grown timer, which is basically a client-side timer, which is backed up by a check to the SQL database to see when their last activity was. This seems to work well for us. It's not perfect, but it allows us to notify the user before the session times out, and allows us to be certain we're not logging a user out before their 60 minutes of inactivity is up.What's happening is that certain users are being logged out after just a few minutes. We've eliminated the timer as a cause and believe what's happening is the HttpContext.Current is null, so the user is logged out. We do not know why the HttpContext.Current is null, and I understand there are many reasons that may occur. What I'm trying to figure out is, is there any way to re-establish the context once it is null? If not, is there anything I can do at this point other than have the user login again? We're also trying to figure out a better way of managing user information (preferences, roles, flags, history, etc), but everything needs context to use, right? Cookies, sessions, cache, etc. all require a response or request, correct? hope this makes sense, because I really need help with this. I've searched the forums here, and found many posts about HttpContext.Current going null, but not a lot of solutions for this...

View 14 Replies

HttpContext.Current.Session Is Null

Aug 20, 2010

I am getting HttpContext.Current.Session is null.Will this be a problem if we have application hosted in web farm.

View 1 Replies

MVC :: HttpContext.Current.Session Item Is Null?

Jan 17, 2011

i'm storing in HttpContext.Current.Session current user, SiteUser is single-tone class that presents current active siteuser, and when he logged i'm creating new SiteUser() in controller and in constructor adding him to the session:

[Code]....

then, with every request to the server services i'm check is user available in session:

[Code]....

otherwise i'm generate non-auth-user exception and redirect him to the logon page. but sometimes HttpContext.Current.Session[sessionKey] is null, but HttpContext.Current.Session doesn't null and FormsAuthenticationTicket is available and Expired property is also false. can somebody help me, why HttpContext.Current.Session[sessionKey] can be null?UPDi have downloaded symbol tables of source .NET Framework and set breakpoints at SessionStateItemCollection on changing collection items. and i resolved some mistakes:1) all collection items are null — "culture" is setting up after2) it happens at the session end eventi can't understand how it can be, because at web.config session timeout is set 20

View 20 Replies

Why HttpContext.Current.Session Is Null In Global.asax

Nov 15, 2010

I'm using VS2010 and created a simple asp. web forms application, using Development Server to test it. I try to store user data - queried from sql server - in the session, since I don't want to access database in every request. I'm using the 'Application_AuthenticateRequest' and the 'Session_Start' methods.

First round:

AuthenticateRequest called. The following code ran:

[Code]....

The _current variable is a private static field published through a static property. In the first round the Session is null, and I think it's ok because the Session_Start not called yet. The Session_Start looks like this:

protected void Session_Start(object sender, EventArgs e)
{
Session["EMPLOYEE_DATA"] = EmployeeFactory.Current;
}

In the next round the Session_Start is not called of course but in the AuthenticateRequest I can't access to the session. The HttpContext.Current.Session is null and the this.Session reference throw a HttpException says the "Session state is not available in this context".

However I can access the Session from any of the page_load events but it's a bad practice I think that I put authentication every page_load.

View 1 Replies

State Management :: System.Web.HttpContext.Current.Items Not Working?

Jul 21, 2010

In a page (not default) I have:

Protected
Sub Page_Load(ByVal sender
As
Object,
ByVal e
As System.EventArgs)
Handles
Me.Load
Try
loginRep = BusinessLogic.SR.GetUserName("99999")
System.Web.HttpContext.Current.Items.Clear()
System.Web.HttpContext.Current.Items.Add("RepId",loginRep)

I don't any errors and when in the run in the immediate window:

? System.Web.HttpContext.Current.items("RepId") in the immediate window on THAT page I get the OBJECT.

Then I have a hyperlink with navigateurl to the next page "~/ActCnt.aspx"

On that page, ActCnt.aspx, when in the code I have:

Protected
Sub Page_Load(ByVal sender
As
Object,
ByVal e
As System.EventArgs)
Handles
Me.LoadIf
Not Page.IsPostBack
Then
Dim loginRep
As BusinessLogic.SalesRep = System.Web.HttpContext.Current.Items("RepId")

In the immediate window ? System.Web.HttpContext.Current.Items("RepId") returns a String that is equal to "RepId".

Even if I change it to not be an object, but a string I only get the Name "RepId" of the keypair. I have NEVER gotten the actual value.

View 2 Replies

State Management :: Retain All HttpContext.Current Data After Redirect/transfer To Another Aspx Page?

Jun 9, 2010

What is the easy/safe way to get all HttpContext.Current data (like querystring, etc) in the previous page, after response.redirect or server.transfer to another page?

I am using .net 3.5

View 1 Replies

Difference Between ControllerContext.HttpContext.Session And HttpContext.Current.Session

Nov 23, 2010

i'm using an example in which i can fake the session.It's for use in a unittest of a mvc controller.In the test i create a controller and then i do this:

FakeHttpContext httpctx = new FakeHttpContext(null,null,null,null,mSessionItems );
ControllerContext ctx2 = new ControllerContext(httpctx,new RouteData(), target);

here mSessionItems is my session and target is my instance of a controller,and indeed, when i'm in a controller reading this.ControllerContext.HttpContext.Session, i have a session, great!but.... i also read the session outside the controller, and there i use HttpContext.Current.Session, and that is null (or actualy, the HttpContext.Current is null).

View 1 Replies

State Management :: Session State Returning Null Values?

Apr 29, 2010

I have a clear button and a textbox in an aspx page. I set the session variable in this page as

String str = Textbox1.Text;

Session["TypeIds"] = str;

and I clear the sessions in a clear button event as

Session["TypeIds"]=null;.

Then when the user types some value in the textbox ,on Response.Redirect on another aspx page, the session variable returns null values.It does not retain its session state. The session state has to be maintained in the next page. Is it because this clear button event and setting explicitly to null creates this problem?

View 7 Replies

State Management :: Session State Blank (not Null) After Deployment?

Nov 8, 2010

On my development machine, the session state data is retained after a post back to the server. (XP VS 2008) (This is true if running from within VS or if running in browser with localhost.)On the deployed test server, the session state is blank in IE, but works in Firefox. (Svr 2003 IIS 6)Both machines are running the exact same code with the exact same imputs and same web.config. There is no code between the post backs that write to the session state.Newest addition to the server would be the consumption of a WCF web service. Could this be a symptom of something missing on the server(s) when trying to connect with WCF? I could not find any information other than installing the 3.0 framework. I have 3.5 SP1 installed on the test server.

View 2 Replies

State Management :: How To Check For A Current Session

Jan 20, 2011

I am trying to write a code that I can attach to a .aspx page using <!--#include file="newcode.aspx"-->. What I am trying to do is check to see if they have an current or active session and redirect them if they don't. It seems like this should be pretty
simple, but I have not been able to get anything to work. This is only being used on One page. What I have tried is:

[code]...

View 5 Replies

State Management :: Possible To Get Current Session Timeout Value

Oct 6, 2010

I have a section in my web app that displays the user's name, the current datetime and a logout link. What i would also like to display is the time left for the session.Is this possible? I'm using an ajax timer to give the user the real time, so if i could display also the time that is left for the session to end would be great.

View 6 Replies

State Management :: Null Session In IE But Not FF After Deployment

Feb 17, 2010

I have an app that worked perfectly in development (Visual Studio 2008 Dev Server/Vista), was setup to use cookieless sessions in the web.config, which worked fine. Now rolled out into production (win2003/IIS6) configured as a Virtual Directory. But I'm having Null session issues after a button click. The problem doesnt persist in FF but in IE8. I tried to change session state to cookies and cookieless (InProc) with no go.
[Code]....

View 6 Replies

State Management :: Session Null On Url Routing Asp 4

Jan 15, 2011

I am having session null on url routing , I searched the net all solutions are mostly for asp.net 3.5 , am using 4.0.... i dont have modules tag in web.config , i've got httpmodules which doesnt have that property.

View 3 Replies

State Management :: On Redirect Session Goes Null?

Jul 30, 2010

In certain pages when i try to rediect to a perticular page the Session automaically gets assigned to null, have no idea why is this happening.-No where I'm using Session.Remove or Session.RemoveAll.-Also not even using EnableSessionState="true" or "false" as by default it will always be true, I know...

View 3 Replies

State Management :: Session Is Automatically Getting Null Value?

May 24, 2010

At the login page i m using

adminlogin.aspx
Session["Admin"] = txtUserName.Text;
response.redirect("admindefault.aspx");

[code]...

View 10 Replies

State Management :: Session Became Null - Maintain Data?

Aug 17, 2010

I have a requirement where i need to download mutiple files as a single zip file.There is linkbutton named HOME as well in the page. when this linkbutton is clicked it should redirect to homepage.aspx. I found a ICSharpCode.SharpZipLib.dll in net and used in my website. Here is the code

[Code]....

With the above code i got the expected result i,e. i can zip the files and save on client system. But the problem is after saving/canceling the zip file if user clicks on linkbutton in the page_load event Session[getdata] became null. there is no data in Session. what might be the problem? Actually it should redirect to homepage.aspx but its going to login.aspx because Session[getdata] is null.

View 4 Replies

State Management :: Session Key Gets Null While Object Alive

Jan 27, 2011

I have a Authorizeclient.aspx.cs page where I set my session value.Authorizeclient.aspx is a blank page. HttpContext.Current.Session["nodeID"]="0". This session value changes from 0 or non zero which depends on the value returned by Database. If no value is returned I assign HttpContext.Current.Session["nodeID"]="0" as the default state else I assign HttpContext.Current.Session["nodeID"]=resolve(nodeID).ToString()

Till this part it works fine as expected. However, I have a requirement that I need to read the nodeID from Session in other application on the same server. I mean this application too is part of the root project where I initially created the Session and set it. The strange thing is the Session["nodeID"] in application gets null "SOMETIMES" Not always. I am trying to read the Session in Page_Load. Sometimes it works fine and sometimes it gets null. Moreover the session object do not die and I can see other keys like Session["Themes"] etc there. The session is in InProc mode and have 20 minutes timeout time.

View 6 Replies

State Management :: Session Suddenly Become Null - Need To Rebuild

Jul 28, 2010

I have a strange problem with the session. I have global.asax with code in the session_start event. This code calls some code that I have in a helper class. When I first run the project in debug everything is fine. However when I stop debugging and then re-run the project it fails and I have discovered that once the code in the helper class is hit the session is null. If I look in the global.asax session_start code the session is instantiated before it enters the helper class. If I then re-build the project and the re-run it everything works fine again! Why does the session suddenly become null and why does a re-build fix the problem?

View 3 Replies

State Management :: Session Parameters Are Null In An IFrame

Jan 30, 2011

I have a "one page application" (ASP.NET 3.5, VS 2008, IE7) that uses Default.aspx as it's page, and holds an iFrame within "floating panel" (asp:Panel with extenders).

As the desired behavior is to allow users to reopen the application by refreshing the page,

I added this to the Default.aspx.cs:
protected override void OnPreInit(EventArgs e)
{
if (!IsCallback && !IsPostBack)
{
Session.RemoveAll();
GeoApplication.DAL pDAL = new GeoApplication.DAL();
Session["DALinstance"] = pDAL;
}
}

However, when the iFrame page lifecycle starts, the Session["DALinstance"] parameter is null. I've tried to put some additional parameters and those were null as well.

View 5 Replies

State Management :: Session Value Becomes Null After Redirecting To Different Page?

Aug 4, 2010

I have logged in to the application and naviagate to Resource Editor page where it allows user to enter the value and saves to the resource file of the application.

After user clicks save button and navigate to different page the session value becomes null.

If the user navigate to different page without clicking save the session variable has its value

View 3 Replies

State Management :: Session Value Null In Master Page?

Jun 10, 2010

Im trying to use code provide in this link below.http://www.codeproject.com/KB/aspnet/MultipleTabWindows.aspxim trying to have the below code in my master page instead of adding to each page. it works if i add to each page, but when i add to ,master page the session value for "WindowName" is always null.how can i fix this?

<script language="javascript" type="text/javascript">if(window.name != "<%=GetWindowName()%>"){ window.name = "invalidAccess"; window.open("InvalidAccess.aspx", "_self");}</script>public string GetWindowName(){ return Session["WindowName"].ToString();}

View 6 Replies

State Management :: Session Used In Thread Class Return Null

May 5, 2010

I want to use session in thread class but it return null in parent that is the page class.

View 4 Replies

State Management :: Session Values Automatically Set Into Null In Masterpage

Dec 16, 2010

In my application, session value automatically set into null.In certain workflow only it will set as null (Normally It's able to access value). Example, at the time of login, I will set session values. While, user deleting some entries from drop down list of specifc page,client script will show message like selected entry deleted. After that, flow point will move to master page. There I have to access session variables. It's getting null value. I tried to debug with Quick watch, at the pageload of master page only value set into null (automatically).

View 6 Replies

State Management :: Session Null Empty / Sending Error

Mar 30, 2010

Can anyone explain to me why this first example works fine but the second, which would use a little less code and in my mind appears to achieve the same result, yet throws a null ref error?

This works ...

if (Session["sid"] == null || Session["sid"].ToString() == "")
{
// session is NOT valid.
}
else
{
// session is valid.
}

This does not work?

if (String.IsNullOrEmpty(Session["sid"].ToString()))
{
// session is NOT valid.
}
else
{
// session is valid.
}

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved