My ASP.NET 1.1 application is using load balancing servers. Before load balancing servers, there is no problem related to session management. After googling, I found the following two points:
1) Website instance ID must be same on both the servers. When I ran Microsoft provided VB Script to check instance ID. On both the servers, they are same.
2) I have also generated a unique machine key and pasted it in the machine.config on both the servers.
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.
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...
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?
My web application is hosted on a loadbalanced and whenever the requests are routed to one of them(say Server B), the request fails. Now I want to redirect my requests to the working server (Server A) which always works.
I want to do it via the HttpContext.Current.Server = "ServerA";
How can I do this. Do I need to create a new HttpContext Object ?
I've got a web application that runs of a state server. It looks like soon it may need to distributed and there will be two web servers behind a load balancer.
This works great for session state but my next challenge is Cache
My application leverages heavily of cache. I understand ASP.Net 4.0 will be offering more here but nothing much has been said about the how too.
There are two challenges that I face
1). Each webserver will have its own copy of cache whereas it would be more efficient to put this to a third server the same as session state is put to state server.
2). The real challenge is keeping cache in sync if a simple dataset derived from the database is changed my code dumps that cache item and reloads the cache. That's all well on one webserver but webserver number two wont know to drop that particular cache item and reload it. This could cause some unexpected problems in the application.
For scenario number 2 I could attempt to do some smart coding so server number two knows to dump the cache and reload it.
My guess is someone else has already been here before and there's probably a better implementation approach rather than writing extra code.
Does anyone know how I could achieve the goal of keeping Cache in sync between multiple webservers or even better farm Cache management to another server?
I am doing a POC of making my website run faster. Currently it stores huge object data in Session while passing information from one page to another. What I was thinking is to use shared methods and properties instead of session. It works, but wanted tocheck if this is an optimum way to do it. Below is the code that does not use session but still pass object data from one page to another:
i have a form on page1.aspx with several controls (textbox, dropdownlist, etc).on Page1 PageLoad event i load data from database and performe databinding.From Page1 a user can, by clicking a specific button, move to Page2.aspx to insert some details and, after saving details, he returns to page1.
if save changes are made on control on page1 before save them to db, obviously, these are lost on return from page2 (because are reloaded on pageload from db).How can i save control status between pages round trip?
I am using JavaScript's PageMethod functionality where I am invoking a PageMethod which works like a gem. However I am having an issue in accessing the HttpContext's state which returns me a value "SYSTEM" for
HttpContext.Current.User.Identity.Name
which is not the actual current User Name.
I know there are couple options like storing HttpContext.Current in a Session or saving Context's state in some other custom container but given a web farm environment I am assuming that this will not work as expected.
Here is the code I am working on with
function MyFunction(){ PageMethod.MyPageMethod(); }
here is the signature of the server method
[System.Web.Services.WebMethod()] public static void MyPageMethod() { // gives me "SYSTEM" var user = HttpContext.Current.User.Identity.Name; }
Also if I use the above code to access user name in OnLoad event of the page then it works fine and returns me the CurrentUserName.
I am trying to get the above code to work in an ASP.NET Webform... :)
So I am wondering if there is a way to access the current actual user in page methods without making use of sessions.
I've always wondered how you can access the correct state of the current http context via a static method:
HttpContext.Current.Session["foo"] = "bar";
In any other program, anywhere else, my initial assumption about working with a static accessor like this is that changing it will change it across all threads. Similarly, another thread running my change it on me while I am trying to use it.But HttpContext.Current does not behave like this. It provides the appropriate state for the given request, even through the static accessor.
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
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.
Let me explain, describing the scenario:In a custom server control (in my case, derived from CompositeControl), in the overidden CreateChildControls method I create a complex tree of subcontrols, using information from a db.The db provides both information on which controls I need to create (the user interface's structure) and the data used to fill these controls.Than the user can interact with the control and change the data (that becomes different to what stored on db).
My custom control lives in the same page where there are other controls, obviously.And these controls can cause a postback at any time.What I need is that my custom control keeps the data entered by the user across these postback, without reverting to the original data and loose the user data entry.
Here is the first doubt:
1)I create the subcontrols dinamically in the CreateChildControls at any page refresh (both on first call than on postback).I know that the framework solves the reference between the posted data and the controls I create in the CreateChildControls in order to set properties and raise control events, but can you tell me when and how it actually does this? In which phase of page life cycle? What happens after the CreateChildControls?
A second doubt:2)If the user interface structure must change as a consequence of the data entered, I had to execute CreateChildControls twice (the first time to recreate the original interface to get the events and the second time to create the new interface) In which phase of page/control lifecycle do I have to make the second call to CreateChildControls? I do it on Prerender now, but is it right or wrong, and why?
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
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.
I am having a ASP.net application it having three pages ,page 1,page 2,page 3,when the user navigating between this pages I want to maintain the view state in page level after postbacks(i.e.) .If a user visits page 3, passing some query loads some data .then he moves to page 1 doing some entries .after that he once again moves to page 3 now I want to display the data previously available at the time he moves to page 1, same way I want to do to my three pages up to the user logging out.
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?
I'm still debugging my application so it's on the local server. As I debug and stop then debug again, eventually lblNoOfUsers.text turns to "0" instead of "1", even as I'm navigating my application. It only turns to "1" again if I log out and sign back in. It's almost as though Membership.GetNumberOfUsersOnline my login are referencing two different session states. How is this possible? Does asp.net create a new session state cookie each time I start debugging?
All we have a global ships position tracking website which runs smoothly until IIS application pool recycles.When there is workerprocess recycling looks like session state expires as a result i loose all session data and when customer clicks refresh button he is redirected to login page.
In web.config Session state mode is set to InProc so i changed it to State Server but to my luck i have MAP object which is not serialiazable which is causing the maps from not appearing on the website.I tried adding serializable attribute to the object class but still not succesfull.Our website is accessed by our customers whose count is more than 1000.
Changing the session state mode from InProc to StateServer can really slow down the response time so Is it good to go further fix the serailizable issues and move to state server?.
Is there any way I can retain my session data when application pool recyles?..
Stopping Application pool from recycling may not be a good idea considering health factor of web server.
i have one method which save datatable in viewstate.i am calling this method in. page_load2. Prerenderthe page was every heavy,i did tracing of page i found due to calling of method from preprnder it doubled the viewstate sizewhat was the reseon behind this.