<p>This would be a question for anyone who has code in the App_Code folder and uses a hardware load balancer. Its true the hardware load balancer could be set to sticky sessions to solve the issue, but in a perfect world, I would like the feature turned off.</p>

<p>When a file in the App_Code folder, and the site is not pre-compiled iis will generate random file names for these files.</p>

<pre><code>server1 "/ajax/SomeControl, App_Code.tjazq3hb.ashx"
server2 "/ajax/SomeControl, App_Code.wzp3akyu.ashx"
</code></pre>

<p>So when a user posts the page and gets transfered to the other server nothing works.</p>

<p>Does anyone have a solution for this? I could change to a pre-compiled web-site, but we would lose the ability for our QA department to just promote the changed files.</p>

[{'answer_id': 50780, 'author': 'Michael Haren', 'author_id': 29, 'author_profile': 'https://Stackoverflow.com/users/29', 'pm_score': 1, 'selected': False, 'text': '<p>Does your load balancer supports sticky sessions? With this on, the balancer will route the same IP to the same server over and over within a certain time window. This way, all requests (AJAX or otherwise) from one client would always hit the same server in the cluster/farm. </p>\n'}, {'answer_id': 50782, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 0, 'selected': False, 'text': "<p>If it's a hardware load balancer, you shouldn't have an issue, because all that is known there is the request URL, in which the server would compile the requested page and serve it.</p>\n\n<p>the only issue i can think of that you might have is with session and view state.</p>\n"}, {'answer_id': 50796, 'author': 'Nathan Lee', 'author_id': 3453, 'author_profile': 'https://Stackoverflow.com/users/3453', 'pm_score': 0, 'selected': False, 'text': '<p>Its true the hardware load balancer could be set to sticky sessions to solve the issue, but in a perfect world, I would like the feature turned off.</p>\n'}, {'answer_id': 50825, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 2, 'selected': False, 'text': '<p>Do you have the &lt;machinekey&gt; node on both servers set to the same value?</p>\n\n<p>You can override the machine.config file in web.config to set this. This needs to match otherwise you can get strange situations like this.</p>\n'}, {'answer_id': 50999, 'author': 'Nathan Lee', 'author_id': 3453, 'author_profile': 'https://Stackoverflow.com/users/3453', 'pm_score': 0, 'selected': False, 'text': "<p>It appears that the  is only for ViewState encryption. It doesn't affect the file names for auto compiled assemblies.</p>\n"}, {'answer_id': 51268, 'author': 'JasonS', 'author_id': 1865, 'author_profile': 'https://Stackoverflow.com/users/1865', 'pm_score': 1, 'selected': True, 'text': "<p>You could move whatever is in your app_code to an external class library if your QA dept can promote that entire library.  I think you are stuck with sticky sessions if you can't find a convenient or tolerable way to switch to a pre-compiled site.</p>\n"}, {'answer_id': 190601, 'author': 'William Yeung', 'author_id': 16371, 'author_profile': 'https://Stackoverflow.com/users/16371', 'pm_score': 0, 'selected': False, 'text': "<p>I think asp.net model has quite a bit dependency for encryption and machine specific storage, so I am not sure if it works to avoid sticky IP for session. </p>\n\n<p>I don't know about ASP.NET AJAX (I use MonoRail NJS approach instead), but session state could be an issue for you.</p>\n\n<p>You have to make sure session states are serializable, and don't use InMemory session. You probably need to run ASP.NET Session State Server to make sure the whole frontend farm are using the same session storage. In such case session has to be perfectly serializable (thats why no object in session is preferred, you have to always use ID, and I bet MS stick on this limitation when they do AJAX library development) </p>\n"}, {'answer_id': 1133278, 'author': 'CodeRedick', 'author_id': 17145, 'author_profile': 'https://Stackoverflow.com/users/17145', 'pm_score': 1, 'selected': False, 'text': '<p>Ok, first things first... the MachineKey thing is true.  That should absolutely be set to the same on all of the load balanced machines.  I don\'t remember everything it affects, but do it anyway.</p>\n\n<p>Second, go ahead and precompile the site.  You can actually still push out new versions, whenever there is a .cs file for a page that page gets recompiled.  What gets tricky is the app_code files which get compiled into a single dll.  However, if a change is made in there, you can upload the new dll and again everything should be fine.</p>\n\n<p>To make things even easier, enable the "Used fixed naming and single page assemblies" option.  This will ensure things have the same name on each compilation, so you just test and then replace the changed .dll files.</p>\n\n<p>All of that said, you shouldn\'t be having an issue as is.  The request goes to IIS, which just serves up the page and compiles as needed.  If the code behind is different on each machine it really shouldn\'t matter, the code is the same and that machine will reference it\'s own code.  The actual request/postback doesn\'t know or care about any of that.  Everything I said above should help simplify things, but it should be working anyway... so it\'s probably a machinekey issue.</p>\n'}]
['https://Stackoverflow.com/questions/50771', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3453/']