In traditional ASP.NET application, you have option to use several session states mode including In-Process, State Server, SQL Server, or even Custom. In fact, the simplest way and most common scenario is using In-Process where the session states is actually stored in the web server memory.
However, you will definitely face challenges when using in-proc session mode in Windows Azure. As the matter of fact, you may be fine if you are running only with one instance. The reason is because when you have more than one role instance, Windows Azure will create separate VMs for each role instance. As it, each role instance will own their own memory space that is not sync-up amongst other instance-roles. Well, it’s not a good idea to restrict our application to stick to one instance, since probably the reason you choose Windows Azure is the ability to scale in and out elastically.
Alright,let me simply show you why it’s challenging.
1. The first step,I open Visual Studio and simply select New Project – Cloud – Windows Azure Cloud Service. And type in SessionDemo.
2. When the New Cloud Service Project dialog box comes out, select ASP.NET WebRole and change the name to SessionDemo_WebRole, and click OK.
3. In the default.aspx page, I simply insert several ASP.NET component as shown below.
4. Next, go to default.aspx.cs and type the following code:
What it does is just simply display the session value to the screen as well as write it to log by calling Trace.TraceInformation() method.
5. Run the application by click on Run button or F5. Fill-in “Bob” on the textbox and click on “SaveSession” button. When you click on “DisplaySession”, you will simply get “Bob” value which you’ve entered earlier.
6. Alternately, you can also notice the log at development fabric indicate that “New value of session CustomerName : Bob is stored in deployment(495).SessionDemo.SessionDemo_WebRole.0.”
Yes, so far so good. You may change to other value, I guarantee you that it’s still working well as per now.
7. By default, Visual Studio will specify only 1 instance per role. If you need more, you can just simply modify it by click on the intended role and fill in the value of “Instance count:”
Now, change the instance count from 1 to 2.
8. Run your application by pressing F5 / click on Run button. At the mean time, open up your development fabric UI as well. You may want to clear your log to see it more clearly.
As usual, I type “Bob” on the browser and click on “SaveSession”. If you inspect on the dev fabric UI, you will notice that only one of the two role will be handling your request.
9. Click on the “DisplaySession” button to see whether you can see the value “Bob” is display. The answer is maybe yes, maybe no. If the instance 0 who are handling the request, then good that you would be able to retrieve the value. However, it’s also possible that instance 1 is the one who is handling your request. If this is the case, you will see no value displayed.
This proves that the in-proc session scenario doesn’t work in Windows Azure environment.
In the next post, I’ll show you how to use TableStorage Session to workaround this issue.
As most of you have known that, when creating service to host our application in Windows Azure, we are provided a special DNS with suffix .cloudapp.net. For example: http://welypersonal.cloudapp.net/ which is personal starter kit that have been moved to the cloud. You can refer to the series of migration post if you want to know more about it.
It’s very common requirement that we have our custom domain name and want to map it to the cloud-based application. For instance, I have my own wely-lau.net domain which was registered on DynaDot. And then, I would like to create subdomain, namely http://azure.wely-lau.net and map it to http://welypersonal.cloudapp.net.
Steve Marx, the Technical Strategist on Windows Azure blogged this post about it, specifically using GoDaddy as domain registrar . However, we notice that there’s some incorrect image that could lead to confusion. I emailed him before and he said he will fix it later on. We hope so Steve, as there’s so many people refer to your blog .
In the post, Steve mentioned that, in general there’re 2 ways to map domain to point to a location.
In this post, I’ll show you how to map your custom domain to Windows Azure. In order to follow my instruction, you will of course need to own your domain. You can buy or register your domain with some domain registrar such as GoDaddy, DynaDot, Register, etc.
In this example, I’ll show you how to do it in DynaDot, since my domain wely-lau.net was registered there. If you are using other domain registrar, no worries. I believe more or less, the functional and features are the same, just look for it carefully.
1. Log in to your domain registrar portal.
You should see some summary info of your domain subscription.
2. Go to Domains tab, then click on the domain that you wish to map.
3. Click on the value of the name server, which your Domain refer to.
4. Now, you can find appropriate record type and map it to your intended location.
As you can see from the screenshot above, I create a sub domain “azure” by using CNAME record and map it to “welypersonal.cloudapp.net”.
5. When ready, click on the “Use DynaDot DNS” to apply.
Do note that, I takes a few minutes to apply new domain setting.
6. Here’s the screenshot after a few minutes
I hope this post is useful for you .
I’ll post more Azure-related post in future. Stay tuned here.