Solved

Multiple Servers / Persistence of variables / ASP.NET

Posted on 2004-04-18
7
997 Views
Last Modified: 2013-11-25
Heres the scenario .... I have an existing application written in standard ASP, this app runs across two different servers which are "fed" by a load balancer on a "round robin" basis. I had problems with the existing app whereby I couldnt use cookies / session variables as once the user is passed to the other server the cookie / session variable is no longer valid. Therefore I had to use a combination of hidden fields / passing user info in querystrings. This is very very messy !!

I have started to re-write in .NET (ASP/VB) and would like to know if there is a smarter way to get around this issue .... for example .. if all my redirects to other pages are within the "code behind" section will the request actually hit the load balancer and go to the other box ... therefore as long as page navigation was done in the "code behind" the user would stay on the first server they actually logged into rather than bouncing between the two ?!?!?

I've only recently started developing in .NET so please be gentle with me in your responses :-) But as this is a fundamental part / problem in the code its something I need to know from the outset rather than having to go back and rewrite later when (and if) I'm a bit more savvy :-) I've got an itch to get going on this hence the high points !

Thanks in advance

Rob
0
Comment
Question by:robert_f
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Accepted Solution

by:
esandler earned 250 total points
ID: 10853149
In ASP.NET you have two options:

1) Save the session state on a dedicated computer.
2) Save the session state inside an SQL server.

In both options all the variables you save in the Session State must be serializable, which means you can't save COM objects in the session state.

Both options are configurable in the web.config file in the sessionState section.

You have an option of saving all the data in the ViewState of the client, but that will cause the data to be sent everytime from the client to the server, similar to what you have now in a speicialized hidden field. This is not very recommend since the first two options are better.

You also have an option if you have a smart load balancer to perform load balancing but to direct a certain session to the same server which created it. This way its not a full load balancing, but if you got 100 users 50 will go to one server and 50 will go to the other and the load balancing will be done according to a session base and not per request.

This option is also applicable to your current ASP application.

Hope it helps.
0
 
LVL 7

Expert Comment

by:TheKenman
ID: 10854003
Hi robert_f,

Although I know you're wanting to field opinions re: .net, have you tried cookies? ...or do those not travel between the 2 servers either?

-Kenman
0
 

Author Comment

by:robert_f
ID: 10854134
CD&

I will bow to your expertise :-) .... if you could drop it into the .NET topic area that would be good

Kenman

I believe I read somewhere that cookies didnt "travel well", also it would be holding things like user id's, e.g. ADMIN1 , ADMIN2 etc ..... I wouldnt want anyone getting clever and trying to find out what would happen if they changed it to ADMIN3 or something. I would prefer the session approach as nothing ends up on the users machine but it is something to think about and would still be better than the existing method of passing ID's thru the querystring etc as I'm having to encrypt all the variables before populating the string and then decrypt them again at the other end for use.

esandler

I'm going to drop a line to our hosting company about using the load balancer to direct the sessions as that would solve the problem fairly easily ... I'll let you know (and allocate the points :-)) if its possible ... however could you clarify what you mean by   "Save the session state on a dedicated computer" ..... ?

Thanks all

Rob
0
 

Author Comment

by:robert_f
ID: 10857137
Ah ha !!

esandler

I think I've partially  answered my last question .... in the web config file where you have :

stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes;"

Can you just set the stateConnectionString to the machine you want to store the sessions on ?? e.g. on both web boxes set this to 192.168.1.1 and likewise for SQL ? If they are stored in SQL I assume you need to create a Db to hold them and point the connection string at it ? Would you then also need to remove the "storage type" your not using (i.e. if I'm using SQL remove the stateConnectionStringLine)  ? ...... and finally .... if this is the case do you know of any performance benefit from using either one ?

Thanks

Rob
0
 
LVL 20

Assisted Solution

by:ihenry
ihenry earned 250 total points
ID: 10937337
>> Can you just set the stateConnectionString to the machine you want to store the sessions on
Yes you can, for example:
sqlConnectionString="data source=MySQLServer;user id=<username>;password=<strongpassword>"

>> If they are stored in SQL I assume you need to create a Db to hold them and point the connection string at it ?
You have two options here, by default .NET framework comes with four installation sql scripts,
1. InstallSqlState.sql and UninstallSqlState.sql, to create the table in tempdb database
2. InstallPersistSqlState.sql and UninstallPersistSqlState.sql, which create a dedicated database.

More information:
1. HOW TO: Configure SQL Server to Store ASP.NET Session State
http://support.microsoft.com/default.aspx?kbid=317604&product=aspnet
2. HOW TO: Configure ASP.NET for Persistent SQL Server Session State Management
http://support.microsoft.com/default.aspx?scid=kb;EN-US;311209
3. ASP.NET Session State
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspnet/html/asp12282000.asp
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question