find a location for property in a new city

Saturday, 7 January 2012

Do not use iisreset in Azure

So you have remote desktop in to one of you Azure instances and you are free to do anything you like right? Wrong! Do not change things! And as I found do not use IISReset.

I have heard many times that remoting in to an Azure instance is for looking and debugging only, NOT for changing things. In fact I have even given this advice to many clients I have spoken to about Azure. But who am I to practice what I preach?

Really, I give the advice of not changing things when RDPing into an Azure instance because any changes you make will at some point be lost when your instances are automatically updated for you and then redistributed to other machines. Any changes you wish to be permanent on your machine will need to be part of your package.

Anyway, you can see why I avoid making changes, because of a lack of persistence but that doesn't mean I shouldn't do a cheeky IIS reset when trying to fix an issue right? Hmm, wrong.

Do not restart IIS on an Azure instance

I do not know why, there must be some black magic Azure voodoo that goes on after IIS is initialised that doesn't happen when you restart it yourself manually. Anyway, I learnt that it will completely destroy your instance. The site will not respond any longer from that instance. The best way to effectively do an IIS Reset is to Reboot your instance from the Azure Management Portal.

Follow britishdev on Twitter

Friday, 6 January 2012

How to run Crystal Reports on Azure

Here is a step by step guide on how to make an ASP.NET project that uses Crystal Reports run successfully on Azure. If you try to run a Crystal Report in your ASP.NET site without the Crystal Reports runtime installed you will receive a "System.Runtime.InteropServices.COMException" with description "The Report Application Server failed".

The problem is that you need to install the Crystal Reports runtime. This isn't a problem with regular hosting since you can just install Crystal Reports on each of your servers and off you go.

With Azure, though, if you remote into the machine and install it, it will work fine until your deployment is redistributed to another machine which it will do at some point due to the nature of cloud computing.

How to install Crystal Reports on your Azure web role

Fortunately it is still easy with Azure. Easy when you know how anyway. Here are the steps you will need to take:

First of all you will need to download the SAP Crystal Reports runtime engine for .NET Framework 4 (64-bit). This should extract as a msi file called CRRuntime_64bit_13_0_2.msi.

In your web application in Visual Studio you should paste this msi file at the route of your web project and include it in the project. Right click it in the Solution Explorer and set its 'Build Action' to 'None' and also set its 'Copy to Output Directory' to 'Always Copy'.

Next you will create a command file to execute this msi file. Create a new text file, call it StartUp.cmd and then save it in the root of your web project (next to the msi). In that file write the following:

@ECHO off

ECHO "Starting CrystalReports Installation" >> log.txt
msiexec.exe /I "CRRuntime_64bit_13_0_2.msi" /qn
ECHO "Completed CrystalReports Installation" >> log.txt

Set the properties of StartUp.cmd to 'Build Action' = 'None' and 'Copy to Output Directory' = 'Always Copy'.

Now in your ServiceDefinition.csdef make this cmd file a start up task by adding the following lines:

<WebRole name="Web" vmsize="Small">
  ...
  <Startup>
    <Task commandLine="StartUp.cmd" executionContext="elevated" taskType="background" />
  </Startup>
</WebRole>

You are now instructing each instance that starts up with your package to run the Crystal Reports msi file that installs the runtime on the instance ready for its use in Azure.

A few Crystal Reports on Azure tips

I ran into a few bits and bobs which caused me unnecessary pain along the seemingly clean process outlined above. I will share them with you in case you do too in no particular order.

  • Make sure your .rpt Crystal Report files are set to Build Action: Content and Copy to Output Directory: Copy always.
  • Don't be alarmed with how long it takes to deploy. It will take much longer to upload than usual because you are now uploading an extra 77MB of installation files. It took me an hour to deploy on my home connection!
  • Ignore all the warnings about how your web project is dependent on various Crystal Report assemblies since Azure will have them just as soon as your installation file runs.
  • Configure a remote desktop connection when you do your deployments since it will be invaluable should anything go wrong and at an hour per deployment you don't want to be messing about.
  • Visual Studio may have added a load of random assemblies in your web.config you are not aware of and don't need and may even cause problems like log4net.

That is all. Good luck - it's very satisfying when you get it going.

Follow britishdev on Twitter

Wednesday, 4 January 2012

Azure AppFabric Cache billing

I have started using Windows Azure AppFabric Cache service recently and I was confused at how much money it was costing.

I started using a new subscription yesterday and I seem to have already used 53.68 MB of my 128MB cache. In one day?!

However, if I look at my cache in the Azure management portal I am not using it at all!

So where has this 53MB of AppFabric Cache come from? Since I've only put my site live for less than 24hrs I was worried I was blazing through my 128MB/month allowance but then I thought about it logically for a moment. You don't use up a cache you just use it. It doesn't go anywhere.

How AppFabric Cache usage is calculated and billed

With this in mind it becomes obvious what has happened. I set my AppFabric cache up before I got around to deploying my site. So really it has been used since 22nd December, which is 13 days ago. It is irrelevant that I have deployed a site onto it only yesterday.

Look at the maths: 128MB/31days = 4.13MB/day * 13days = 53.68MB. It is a confusing way of displaying it but still, it makes sense.

Follow britishdev on Twitter

Tuesday, 13 December 2011

Understanding Windows Azure spending limits

If you have logged into the Azure billing portal since 12th December 2011 you will have noticed it has had a facelift as well as some changes to its functionality. Particularly a billing spending cap.

I just wanted to share my findings on the new feature of spending limits. Now there will be a $0 spending cap on your account when you sign up for a free trial. This ensures you will not be charged during your free trial. Beware though that once this cap is met your free trial service will stop working and you know that will happen just before you prototype demo.

Let me just clear up some things because I was a bit confused with exactly what had changed until I did some digging about. Mainly because my imagination just invented how the spending caps should work and partly because it is difficult to find documentation on this.

If you set up a new free trial FROM NOW you will get the $0 spending limit. If you had one before (presumably 12th Dec) you have a little note saying you have removed the spending limit. You didn't, you just never got the limit because you registered for a free trial before that the spending cap facility was available. Confusing notification at fault really.

So here is what I found on the payment caps:

  • If you are not on a free trial you have no spending cap and you cannot create one ($0 or otherwise)
  • If you are on a free trial since before 12th December 2011 it will say you removed the spending limit
  • If you joined a free trial on or after 12th December 2011 you will automatically have a $0 billing limit
  • If you remove the $0 spending charge limit you cannot put it back

My thoughts

I think it is a nice idea to keep people reassured that they will not be billed during a free trial. I understand some people felt hard done by when they were charged during this evaluation period (despite how well communicated and fair the free trial usage limits were... but anyway).

However, I think the Azure team has missed a trick here. Why not allow people to set custom spending limits on their accounts? It'd be very nice to be reassured that I would not be billed more than £x a month if I had a fixed budget. It seems like the infrastructure for such a feature is there but just missing the implementation at this time.

Maybe in time the ones of us willing to invest in Azure will get the same reassurances as the free trial users?

Follow britishdev on Twitter

Wednesday, 7 December 2011

Where are my .NET certificates and their thumbprints? Ask Powershell

I ran into a confusing situation where I was trying to pass a certificate with a PowerShell command but found it incredibly confusing to find my certificates.

I was trying to use a certificate on my local machine that I created at an earlier time but where the hell are they? If you open Microsoft Management Console (type mmc into the start bar) and then add the certificates snap in. Choose either Current User or Local computer or whichever is most relevant for you.

Let's dispel some weirdness. My = Personal. For some hilarious reason there is no 'My' folder and it is actually called 'Personal'. This is the place you should be looking for for your own certificates you have created.

So if you have found the certificates you were after you will probably need the thumbprint... but it is encrypted. Awesome.

If you open up PowerShell and type the command

get-childitem -path cert:\CurrentUser\My
this will list all of the certificates in the Current User\Personal folder for you by thumbprint. Very handy. For the ones in Local machine simply replace CurrentUser with LocalMachine.

Hopefully this will save you some time when dealing with this confusing certificate nightmare.

Follow britishdev on Twitter

Tuesday, 29 November 2011

Conflicting versions of ASP.NET Web Pages detected

I was going through the Windows Azure Platform Training Kit, Exercise 1 of the Service Bus Messaging lab and I ran into the following error message when trying to run my site, "Conflicting versions of ASP.NET Web Pages detected: specified version is "1.0.0.0", but the version in bin is "2.0.0.0". To continue, remove files from the application's bin directory or remove the version specification in web.config."

I checked the web.config and the assembly specified was indeed 1.0.0.0: <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />.

When I checked the System.Web.WebPages reference in my project though it also said its version is 1.0.0.0. So what's the problem?

System.Web.WebPages.Deployment

The assembly System.Web.WebPages.Deployment was referenced in my project and on closer inspection it was version 2.0.0.0 so it must be this which is causing the problem. I do not need this assembly though so I deleted it and the error went away.

Follow britishdev on Twitter

Monday, 28 November 2011

Service 'SQL Azure Data Sync Preview' failed to start

While trying to install and start the SQL Azure Data Sync Preview Service I ran across the error message "Service 'SQL Azure Data Sync Preview' (SQL Azure Data Sync Preview) failed to start. Verify that you have sufficient privileges to start system services." Here are the step I had to take to make it start working.

You have to get all of these right to be able to install and start the service successfully. Most are not very obvious and the final step I seem to be the only person on the internet with this problem (hence the blog post)! Anyway, here goes:

Get your username and domain right

Although it says you can enter the account with examples of "domain\user, .\localuser", you can't; it is a lie! You should ensure that you fill out the "User Name" field like MACHINENAME\Username. So MYMACHINE\Colin if you were me.

Verify you have sufficient permissions

Your user may not have permission to log in to Windows Services so you need to make sure you can.

Go to:

  • Control Panel > Administrative Tools > Local Security Policy
  • Open Local Policies > User Rights Assignment
  • Click on Log on as a service
  • Click "Add User or Group..."
  • Set location to your machine
  • Type your user name into the box and click OK then Apply

Ensure you have a password

This was the problem I ran into. The installation just didn't seem to complete because my Windows user did not have a password. I Ctrl + Alt + Del > Change password. I gave myself an actual password rather than leaving it blank which I had done in the past. It then installed without a hitch.

Conclusion

So quite a few snags you may run into when installing the Data Sync service but hopefully with my little check list it wont take you as long as it took me. I'm guessing these sort of bits are just a symptom of the service being in Preview not RTM so they are understandable really.

For what it's worth the preview of SQL Azure Data Sync is a great service, installing this Windows Service was the only issue I had in an otherwise simple process. The benefits of using the service are great, you can sync multiple databases both inside or outside of the Azure data centres. You will only get charged for data leaving the data centre too so any SQL Azure to SQL Azure synchronisation within the same data centre is free! Well, free for now anyway since it is still in preview so I'd keep an eye out when it becomes production ready. Happy syncing!

Follow britishdev on Twitter

Tuesday, 22 November 2011

Share admin login with LiveID in the Azure Management Portal

Has this happened to you? Someone else signed up to use Windows Azure and you are the one who is working on it. You want to access this Azure Portal with a different LiveID? Your LiveID?

Let me guess - your CTO/director decided that Azure is awesome and signed up for its free trial. He had a click around and then quickly passed it on to you, the developer, to work on it. Now you are getting irritated having to remember the new weird LiveID and password and you are tired having to log in and out of your other applications that use your LiveID.

Then the way forward is for you to add a Co-Admin to the Azure Portal. This will allow you to log in with your LiveID that you are used to.

Add new Co-Admin to your Azure account

In your Azure Management portal:

  • Go to the "Hosted Services, Storage Accounts & CDN" tab.
  • Then click "User Management".
  • Click "Add New Co-Admin".
  • Type in your LiveID and select the subscription they can administrate.

Your new LiveID is now added to the list of users and should be a Co-Administrator which has all the power you need to manage the technical side of your available subscriptions.

Follow britishdev on Twitter

Monday, 21 November 2011

Two host names appearing on Google for the same site

If you have an application hosted in Window's Azure your application will have a host name such as mysite.cloudapp.net. You will probably also have a CNAME that points www.mysite.com to the cloudapp. So what if both domains have been indexed by Google? How do you get cloudapp.net URL off of Google?

This is not a problem with Windows Azure; this can happen to any site that has two hostnames/IPs that point to the same site. It is just a recurring issue I see during my Azure consultancy work and worth a quick explanation and solution.

Both mysite.cloudapp.net and mysite.com are pointing to the exact same application and servers so there is no way you can switch one off since they are one and the same, just accessible through two paths. (Well, more than two since they will at least have IP address paths too.)

This issue can be solved in your application code. Your application will need to determine what host name the application has been accessed through and either display the page if the host name is correct or 301 redirect to the correct hostname if the host name is wrong. So how to do it?

301 Redirect cloudapp.net to your correct domain

This can be done in your application by setting a redirect rule using the IIS URL Rewrite Module. There is already a template in IIS's Rewrite Module for doing this called "Canonical domain name" under the SEO section, however I don't particularly like this one since it redirects everything that isn't the correct hostname (e.g. your development machine). Still, you should have a look at it to see what it is doing.

The key steps of what your rule should be doing are:

  1. Check to see if the host name is incorrect
  2. If it is it should issue a redirect to the correct domain name
  3. The redirect should be a 301
  4. The page should remain e.g. http://mysite.cloudapp.net/hello.html -> http://www.mysite.com/hello.html
  5. If the host name is not in violation the page rendering should continue without further action

So you can make your own however you feel is best but here is my example to get you going.

<rewrite>
    <rules>
        <rule name="CanonicalHostNameRule1">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^mysite\.cloudapp\.net$" negate="false" />
            </conditions>
            <action type="Redirect" url="http://www.mysite.com/{R:1}" />
        </rule>
    </rules>
</rewrite>

This code goes in the <system.webServer>...</system.webServer> section of your web.config. Again this is only an example, you may wish to add another condition for handling your IP address for example.

This redirect will solve the problem of any users visiting the incorrect site. Also, because it is a 301 redirect, over a week or two Google will remove the cloudapp.net URL from its search results and attribute its existing value to the correct URL.

Follow britishdev on Twitter

Monday, 14 November 2011

VIP swap with different endpoints in Azure

Attempting to Swap VIPs from the Azure Management Portal can return an message "Windows Azure cannot perform a VIP swap between deployments that specify different endpoint ports" when trying to Swap VIPs between a staging and production environment with different endpoints.

Say you have a web role deployed to Azure and it is currently in production. It has one instance and one endpoint of http on port 80. You then publish a new web role to staging that is also one instance but this time it has an https endpoint on port 443.

Both will work as usual however when you come to swap the VIPs over you will recieve the error "Windows Azure cannot perform a VIP swap between deployments that have a different number of endpoints" preventing you from putting your new site into production.

Is there a way around this?

I tried a few different tactics. I tried doing a straight upgrade to production (since I have tested the same deployment in staging) but this failed for the same reason as above.

I tried changing my new package to have the original http endpoint on port 80 as well as the new endpoint on port 443. This didn't work either. All this experimenting takes time so I thought I would save you the hassle and just tell you that neither of these work!

The only way(?)

The only way I found to get your new site into production is (you guessed it) delete the old site that is to be replaced (scary!), and then click "Swap VIP". You will experience down time for somewhere between 2 and 3 minutes so pick the least destructive time to do this.

Note: Please please test the new site that on staging thoroughly as you just deleted the production package and so it will take a long time to get back!

Follow britishdev on Twitter