Publishing an MVC site to load balanced servers

The purpose of this post is just a few notes to remind me of the steps I followed yesterday when publishing an MVC site to our load balanced servers.

We have three web servers and our hosting company controls the load balancing for us. So, it’s possible that some of the solutions that worked for me might not work for you.

When I first created the website I simply had one simple html page. Checking this page in a browser at first worked but after a refresh showed a 500 error, which took me by surprise. I refreshed the page several times, sometimes it would display, other times the 500 error was shown. The problem here was permissions. Using IIS on one of the servers I went to the site, clicked on Advanced Settings and added the correct account in the Physical Path Credentials. Now, anonymous users coming to this site use this account’s permissions as a proxy. That last sentence sounds complicated but it explains (at least to me) why this step needed to be taken.

I was then ready to publish the actual site, which I did using the Publish facility in Visual Studio. All the files went across but when I tried the site I saw an error saying that it couldn’t find the System.Web.Helpers DLL. My first thought was I just put this in the GAC but then I thought this could be due to MVC not being installed on the server. I found this post by Josh Gallagher, which details quite nicely how to ‘Add Deployable Dependencies’. Doing this meant my site was up and running and I didn’t need to re-start live servers (which simply was not an option!). I also added the <identity> key to my web.config so as my site can access the data stores to get the necessary information.

However, all was not over. My MVC site uses Forms Authentication and I found that whilst I could log in, every so often when I clicked on a link I was being prompted to log in again. This made me think that I was being authenticated on one server but when the load balancer switched me to a new server I needed to go through the process again. The way to solve this problem was to add a <machine key> setting to the web.config file. This has various attributes: the validationKey decryptionKey, validation and decryption. Setting these values and adding this key to the config file solved the problem. So, I could now log in and move around the site regardless of which server was serving the content.

The next problem was more specific to my application. I am using an ASPX page, which has a Microsoft ReportViewer control. During development I did try and see if I could host this within MVC but that didn’t seem possible. Steps that needed to be taken here was making sure the identity my site uses has permissions to see the reports on the report server and adding another setting to the web.config. This time the <sessionState> key. Again this was needed because of the site being on load-balanced servers and getting the message ‘ASP.NET session has expired or could not be found’. After all that I put my feet up and had a cup of tea!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s