C#: Get URL of HTTP Redirect

This is one of those snippets that might be useful someday:

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://this.domain.com/someThingThatRespondsWithRedirect");
webRequest.AllowAutoRedirect = false;
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
string redirectUrl = response.Headers.Get("Location"));

Typically browsers or the default http request class of your favorite programming language redirect you automatically in case they receive a HTTP Redirect status code. Typically that’s exactly what you want.
Last week however I ran into a situation in which I didn’t want the redirect to happen.
Since the code was written in VBScript / ASP, I first tried to accomplish it there. No chance. Good thing that I don’t have to rely entirely on VBScript. The C# WebRequest class has an attribute that allows to explicitly turn off the automatic redirect. You can read the Redirect-URL from the response header.

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in C# | Leave a comment

Bye Bye MacPorts, Homebrew here we go

Having bought my iMac in September 2010, I’m still pretty new to Mac OS X. One of the first things I did back then was to install MacPorts in order to install e.g. the Gimp, Ruby and a couple of other open source software. It all worked great … but… I felt a little bit like a couple of years ago when I first installed Gentoo on my desktop. It’s all about downloading and compiling, downloading – compiling, downloading… you got it.

Installing Gimp through MacPorts took about 45 minutes… not great. Very annoying in fact.

One of the reasons I switched from Gentoo to Ubuntu was that it has a great package manager. After the MacPorts Gimp experience I was hoping there was a great quick alternative for MacPorts, too.

Turns out there is. Homebrew … The missing package manager for OS X. It’s quick, it works, no more compilation … happiness!

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in OSX | Leave a comment

Testing Photoshop Elements

Today I downloaded Adobe Photoshop Elements 9 for testing . After a few hours of trying it out: Great software and I’m pretty sure I’m going to buy it since it’s for only 100 EUR which I consider a fair price for it.

I’m used to the Gimp which is a great image processing software itself. But: the user interface and the overall usability are not any more up to date. You get used to, but while Gimp is awkward to use, Photoshop Elements feels just right.

Here the result of my first trial with the Smart Brush

While the tool is very intuitive to use, here is a useful tutorial: Creating a blue sky

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in Photography | Leave a comment

Setting up a CDN with Amazon S3 and Cloud Front in 5min

When you create a new bucket in Amazon S3, you can choose from five different locations: US Standard, Northern California, Ireland, Singapore and Tokyo.

Most web applications however have visitors from all around the world. So if you choose US Standard, visitors from the east coast will have a very low latency while visitors from Europe and Asia will have to wait longer for the resources stored on Amazon S3.

A common approach to this problem is using a Content Delivery Network (CDN). A CDN consists of many servers all around the world all holding copies of the resources of your web page. So a visitor from the US would get content from a server in the US, a visitor from Asia would receive the content from an asian server and a European from a server in Europe. This guarantees low latency and better bandwidth for visitors from all locations.

I’m using S3 for 3-6-5-days.com with a US Standard bucket. I wasn’t really happy with the latency, but luckily setting up a CDN for your S3 bucket is as easy as pie.

All you need to do is this (I will assume you’re already signed up for S3 and created a bucket):

  1. Sign up for Amazon Cloud Front.
  2. Click on Create Distribution and select the bucket which you want to distribute through Cloud Front CDN)
  3. Now, specify whether you support http and https or only https. Only you can configure whether your resources should be available for streaming or downloading.
  4. On the last screen, hit Create Distribution
  5. You’re done! The distribution is configured now. Amazon will automatically start deploying the resources to the various edge locations, in the US, Asia and Europe.

There are two more things that need to be done outside of the Amazon AWS Management Console:

  1. You need to create a subdomain and configure the CNAME you specified when creating the distribution. So for above example I would create a subdomain like this: cdn.3-6-5-days.com. The CNAME would point to the domain name you see in the Amazon AWS Management Console. It is something like 123xyz.cloudfront.net
  2. Once subdomain and CNAME are configured you’re ready to use the CDN in your web application. Simply make sure that instead of loading resources from the bucket URL you use your new CDN URL. For above exmaple that would be cdn.3-6-5-days.com/path/to/resource/test.css

Here is another good article about the topic: How to Setup Amazon S3 with CloudFront as a Content Delivery Network

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in Web | 1 Comment

Visual Studio 2008: Configuration Manager missing

Today I ran into a problem with Visual Studio 2008: It wouldn’t show me the Configuration Manager in the Build menu which caused that I couldn’t easily switch between Debug and Release compilation.
For the exact same source code and the same version of VS2008 a colleague got the right menu item.

Turns out you need to enable configuration manager! Go to Tools > Options > Projects and Solutions > General and enable the Advanced Build Configuration option.

DeliciousTwitterFacebookLinkedInRedditSlashdotTechnorati FavoritesDiggShare
Posted in ASP.NET | Leave a comment