State Management :: Session State Object Configurations
Nov 9, 2010[Code]....
View 3 Replies[Code]....
View 3 RepliesI want to be able to persist data across a session but do this outside of the built-in session state object. Why is a long story that I will not go into here. I just need to know where I can put data other than in the session object that will persist across the specific session.
View 3 Replies On my local machine I've got a website running which uses the login control to authenticate a user and write a formsauthentication ticket to the client (which is also on the same local machine). At the login process it stores a a small serializable userobject in a session object named Session["appuser"]. Now when I open FF and login to the website all is fine so far... But here's the thing I cannot for the life of me figure out...
When I open IE8 and login to the same website, the session object which was created in FF is completely overwritten with the one created in IE. I thought that every session is unique, but now I'm really starting to feel my knowledge of sessions is almost next to nothing... Is there anyone out there that could tell me why I'm seeing this.
how I can know if a session object was never instantiated?
View 1 RepliesI have a object of Class named "Employee" I need to store the object in the session. what happens if i do not serialize the object and store in the session.
View 7 RepliesI 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.
I am stuck with the issue of concurrent access to Session object. Actually my problem is i m writing to session in frame1 and trying to access that same Session object at the same time in Frame2's Page. I know about the reader/writer lock. I made the enablesessionstate = readonly in the page where i m writing to session. its giving me strange behavior on IE and firefox.
Its working concurrently in IE8 ( means page2 is diplaying modified values while page1 is changing the session object) but does not work in Firefox even page load is not called untill function on page 1 completed. Either anyone can fix my issue with firefox or there is new solution to reader/writer lock so that i can read the session at the same time while writing.
I have a asp.net application where I am saving off into session the user privilege information. From a grid I am bring up a new window by using the window.open. It seems that it is whiping out the values in session. A temporary bandaid I have placed on it is to recall the database if the value is nothing to reset the user object. I have found all over the internet that this is an issue with the window.open in IE 7 and IE 8. Has anyone else run into this and able to actually fix it?
View 4 RepliesSystem.InvalidCastException was unhandled by user code
Message=Specified cast is not valid.
Source=App_Web_donate.aspx.cdcab7d2.wqdohvu3
StackTrace:
at Donate.LoadUserDetails() in C:UsersSimonDesktopLocal SitesCats ProtectionNewDonate.aspx.vb:line 261
at Donate.btnDonate30_Click(Object sender, EventArgs e) in C:UsersSimonDesktopLocal SitesCats ProtectionNewDonate.aspx.vb:line 205
at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
I have made the important bits Bold I have the following code which is generating this error:
[Code]....
I am not entirely sure what is causing it. Its completley intermitent. I am storing all the details of a user filling in a form in a structure, and then assigning that structure to a session variable. This means if they page back, and then page forward again, I can pre-populate the form with the details they have already filled in for their conveinience by using the above code snippet. It appears that it works for a good minute, but if I leave the browser alone any longer than roughly 60 seconds, and then try and page forward to the form again, the exception will fire. While writing this post, the exception has occured in again in firefox, but interestingly, Google Chrome doesn't seem to have this problem. It looks like I can leave chrome alone for as long as I want and it will still work.
I have a Session object
Session["MyListObjects"] = null;
When a user hits a button I want to creat a List<string> object and add to session object.
Let's say if user hits the button 10 times, I would get 10 List<string> objects and
add to Session["MyListObjects"] and
Finally I want to read all the List<string> objects from the session object.
my solution currently has a website project and a class library project. I am attempting to access a session object from my class library but it is always returning null. In a settings class in my class library I store these values like so:
private static SessionProperty<WebUser> _currentUser = new SessionProperty<WebUser>("CurrentUser", delegate { return new WebUser(); });
public static WebUser CurrentUser
{
get { return _currentUser.Value; }
set { _currentUser.Value = value; }
}
I can access this just fine from any aspx page codebehind like so:
Settings.CurrentUser.User.ProviderUserKey.ToString();
However, if I attempt to do the same thing from a class in my classlibrary project it always returns null.
I test my asp.net website app in my win 2000 server in Administrator user mode, the session I start (Session("user_ses") = myclass) only lasts a few seconds. But if I do the same as a 'common' user the session lasts 20 minutes, which is the time I set in web.config file:
<sessionState mode="InProc" cookieless="false" timeout="20" />
which is the reason the session lasts so little in Administrator user mode in windows 2000 server?
User Interface: 2 Labels; 1 Buttons
Requirements: Create a Web Page in ASPx that will do the following:
1)One label will provide a count of how many times Button 1 has been clicked in the current session.
2)One label will provide a count of how many times Button 1 has been clicked by all users of the application. The Application Code for the Button should start at 100 (set this in the Global.asax file). this is what i have so far but i cant seem to get the application state to work properly.
aspx.vb
Partial Class _Default
Inherits System.Web.UI.Page
Dim clickcount As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("ClickCount") Is Nothing Then
clickcount = 0
Else
clickcount = CInt(Session("ClickCount"))
End If
If Not IsPostBack Then
If Request.Cookies("UserName") IsNot Nothing Then
Label1.Text = "Welcome Back " & Request.Cookies("UserName").Value & "."
End If
End If
Dim clickCounta As Integer = CInt(Application("ClickCount"))
End Sub
Protected Sub PostBackSession_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PostBackSession.Click
clickcount += 1
lblClkCnt.Text = "Current Click Count is " & clickcount
Application.Lock()
Dim clickCounta As Integer = CInt(Application("ClickCount"))
clickCounta += 1
Application("ClickCount") = clickCounta
Application.UnLock()
AppClick.Text = clickCounta
Dim nameCookie As New HttpCookie("UserName", _
TextBox1.Text)
nameCookie.Expires = Now.AddYears(1)
Response.Cookies.Add(nameCookie)
End Sub
Protected Sub PostBackSession_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles PostBackSession.PreRender
Session("ClickCount") = clickcount
Application("ClickCount") = clickcount
End Sub
End Class
global.asax
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim clickCounta As Integer = CInt(Application("ClickCount"))
Application.Add("ClickCount", 0)
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
Dim clickCounta As Integer = CInt(HttpContext.Current.Application("ClickCount"))
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
End Sub
The a way to save an object in session with expiry time , such as when you're saving object in cache.
View 12 RepliesI am trying to pass a key value from one page to another, using VB.net and Visual Studio 2008 Professional. I am creating a session variable in one aspx page and trying to retrive the value in the second aspx page (Dircted to by a button with the postbackurl set) However, the session object is empty when I try to access it in the second page. If, however, i put a debug hold on the code which retrieves the variable, and examine the session object from the "locals" debug window, i see contents. When I then resume the application the code retrieves the value correctly. I am executing my code using the development server that comes with Visual Studio. Could it have something to do with that?
First Page:
[Code]....
Second Page:
[Code]....
While working with mutliple tabs of same browser, session varibles/object gets over written with latest one.
Scenario in my application:
I have to create new employee on first tab(tab #1), and updating existing employee details on second tab(tab #2).I stored employee other details in Session["dtInfo"], use it on saving the record.Now Session["dtInfo"] having details of latest tab created, i.e. tab #2. I tried to save record on tab #1, facing the problem of session gets over written.I had to check some vaules on OnInit and OnInitComplete event. But I get here wrong values in session.
I noticed that when i am debugging my web application in Visual Studio 2005 using IIS, after about 10-15 minutes of inactivity, when I do something in the application such as a postback, I get an immediate error saying: "object reference not set to an instance" and my code breaks somewhere.Is my assumption correct that this is because my session has timed out? ( i do have a 15 minute default session time)my next question is, how do I display or set a way so that like many other pages, when the session has expired, a message will say: "This page must be refreshed" or "Your session has expired, click okay to refresh page" and start over again?
View 1 RepliesIve created an object and placed it in the session, then in my .ashx handler I want to get that object from the session. The problem is that its always null !
heres how ive placed the object into the session from an aspx page
[Code]....
I read the solutioin for this error, at the following link :http://forums.asp.net/p/1046935/1576341.aspxbut I am still not clear what exactly causes the error. I have two doubts :1. Can anyone please elaborate a bit on this issue, with any example ????2. Is there any drawback of this approach ?
View 4 Repliesi'm having a gridview with textboxes and i'm allowing user to enter all the textboxes and when submit button is clicked, I'm constructing the Object and adding all the rows to LIST class.,After that i'm putting that LIST elements in a session. Everything is fine, But when i try to cast the session object to LIST type and pass it to XML serialization, I cannot see the elements in the list and it is showing LIST as NULL. I can see the generated XML string with ROOT and my classname as attributes without no data.
Here is the below code:
[Code]....
I have a multiview inside an updatepanel. in one of the views, I save a value in a session object like this:
Session["xyz"] = "some string value";
Then I switch to another view and try to pick it up the value in a button's OnClick event:
string x = Session["xyz"].ToString();
But I get a null reference error. Debugging it shows that Session["xyz"] is indeed null, yet other Session variables are still there. Is there something special about Session and AJAX?
global.asax:-I have defined a struct (my_struct)-I add a List of structs (List<my_struct>) to Application["MyList"] In default.aspx:-I have defined the exact struct (my_struct) and want to cast the Application["MyList"] object to the List of structs.
example: x = (List<my_struct>)Application["MyList"];
I receive this error "Unable to cast object of type 'System.Collections.Generic.List`1ASP.global_asax+my_struct]' to type 'System.Collections.Generic.List`1[_Default+my_struct]'
Customer were getting "View State Validation Error" due to worker process recycling at our production webserver and to fix that i applied machinekey and then move my Session state Mode from In Proc to State Server to retain session data and not kick out the customer to relogin. I had serialization issue with one object which has to be stored in session but when i moved it out of session i could able to resolve the issue.
But doing all these i was partly successfull in keeping the user in their session when Worker Process recycle event occurs.I was able to refresh the page or make a post back by clicking the refresh button and also able to retain the session values. But the Problem occurs when sending asynchronous request to server which we do periodically every 15 minutes from the moment the user logs in.The web page doesnot update data on website when sending asynchronous request.By Debugging I found at this particular code point it fails to make a postback which is required.
<%=GetHintFromServer%> (When there is no Worker Process recycle i t gets replaced by
WebForm_DoCallback('__Page',message,ShowHint,null,null,false) on postback) Everything works fine when there is no Worker Process Recyling but when it happens looks like sending request asynchronously using javascript fails .Remember When I make a post back by manually clicking submit button everything works fine.
SendRequest(Asynchronous)
function SendRequest(msg, isBusy, chartMsg, vesselMsg)
{
try
{
//confirm("msg"+msg+"isBusy"+isBusy+"chartMsg"+chartMsg+"VesselMsg"+vesselMsg);
_busy = isBusy;
if(chartMsg != null)
{
//confirm("chartMsg"+chartMsg);
_element.SetMessage(true, chartMsg);
}
if(vesselMsg != null)
{
confirm("chartMsg"+vesselMsg);
_element.ShowVesselLoading(true, vesselMsg);
}
_stuckWatchdog = setTimeout( "ClearPendingRequest();", 60000);
var message = msg;
var context = '';
<%=GetHintFromServer%>
}
catch(e)
{
alert( "Exception error on SendRequest(): " + e);
}
}
I am new to .net 4.0 and am using EF Model and SessionState Mode=SqlServer and I am getting this error below:
Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.
I checked the stack trace and its complaining about
[assembly: global::System.Data.Objects.DataClasses.EdmSchemaAttribute()]
[assembly: global::System.Data.Objects.DataClasses.EdmRelationshipAttribute("PoplarGroveModel", "tblMenuRole", "tblMenu", global::System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(PoplarGroveDataModel.Menu), "tblRole",
[Code].....
I marked it as serializable but then it complains about System.Data.Objects.ObjectContext is not marked as serializable and hence throws the same error.
Our ASP.NET App uses ASP State Session Management and has been rebuilt about 2 years ago [With .NET Framework 2.0]. We are currently in .NET framework 3.5 and have moved to SQL Server 2008 - but continue to use the same ASPState database. The State database has been upgraded to SQL Server 2008. Since then we have are seeing timouts/locks on ASPStateTempSessions table. I am wondering if we have to rebuild this database from scratch with some newer scripts?
View 2 Replies