X Blogs

who you gonna call?

Bulletproof Cross-Browser CSS Techniques

clock October 13, 2010 18:44 by author Klemen Slavič

I've written up a summary of all tehniques and tricks for cross-browser CSS coding I've learned over the years in a guest post on Script Junkie. It's meant to be a starting and reference point for anyone from beginner to advanced levels.

Have a look.

Using MVC routing to address multi-tenant Azure applications

clock October 11, 2010 19:29 by author Rok Bermež

Currently I have a scenario where I have to have more than one site and multiple domains/subdomains in a single Windows Azure web role.
For obvious reasons Windows Azure give us FQDN (like myapp.cloudapp.net) instead of IP address so we have to use CNAME to point to our instance/s. The only problem with this approach is that only domain name cannot have CNAME record. For instance www.mydomain.org is fine, but just mydomain.org is not since it needs specific IP address. For the time being this was solved by pointing it to some specific address which would redirect the user to www of that domain.

That part was simple and straightforward, but now we need something inside our web role, that would detect requested domain and serve appropriate content. There are a couple of threads online that deal with the issue of addressing multi-tenant application in Windows Azure and most of them deal with url rewriting on the single domain. You can read more about it here and here.

In my project I used MVC Areas to separate different sites so all I needed was MVC routing to use domain name from incoming request in its routing configuration. I found an excellent article on the subject here, but unfortunately it was written before MVC 2 introduced areas, so in order to use it lets add area support to it.

First lets download the sample here, open and if needed convert solution and open DomainRoute.cs. We only need to add one line to the end of GetRouteData method:

if (Defaults.Keys.Contains("area"))
data.DataTokens.Add("area", Defaults["area"]);

so that it looks like:

         if (DataTokens != null)
                    foreach (var token in DataTokens)
                        data.DataTokens.Add(token.Key, token.Value);
                if (Defaults.Keys.Contains("area"))
data.DataTokens.Add("area", Defaults["area"]); } return data; }


And we are ready to register our areas as their own domains/subdomains

        public override void RegisterArea(AreaRegistrationContext context)
            context.Routes.Add("subodomain_default", new DomainRoute(
           new { area = AreaName, controller = "Home", action = "Index",
id = UrlParameter.Optional } ) { DataTokens = new RouteValueDictionary(new {
Namespaces = new string[] { "MvcWebRole1.Areas.subdomain.Controllers" } }) } ); }

 I strongly suggest you pass Namspaces to every route registration so you can have multiple controllers with the same name serving different tenants. Soon Ill add a DomainRouteExtension and post it here so the usage will be even simpler.

About the author

Rok Bermež is Slovenian Windows Azure MVP, he works as a Software Engineer and Microsoft Certified Trainer at Kompas Xnet. His primary interests include cloud computing and web development. With extensive experience in development and architecture he participated in many projects and since the CTP release of Windows Azure much of those projects are based on Windows Azure platform. Rok has been delivering courses, writing code and speaking at conferences and community events on Microsoft technologies for the last couple of years. You can also find him on Twitter (@Rok_B).

Month List

Sign In