locked
CloudBlob.Uri doesn't return custom domain RRS feed

  • Question

  • I set up a custom domain for an Azure Storage and it is already verified. When I create or retrieve a new CloudBlob, shouldn't the Uri property point to the custom domain? I am seeing that the Uri returned is still in the form of [storagename].blob.core.windows.net. Is this a bug or on purpose?
    Wednesday, August 31, 2011 8:22 PM

Answers

  • Hi Jonas,

    > Is this a bug or on purpose?

    It is on purpose. As custom domain needs a CName record in the domain provider. If there is something wrong when configuring the custom domain and if CloudBlob.Uri returns custom domain, we cannot ensure CloudBlob.Uri is a valid uri. To ensure CloudBlob.Uri is always valid, the default domain provided by Windows Azure is used.

    You can write your own code to replace CloudBlob.Uri with your custom domain. For example:

    public static string CustomDomainForBlob(string url)
    {
        string domain = "www.mydomain.com";
        string protocol = "http";
        string baseAddress = string.Format("{0}://{1}/", protocol, domain);
        return Regex.Replace(url, "^(http|https)://([^/]+)/", baseAddress);
    }

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Marked as answer by Jonas Stawski Thursday, September 1, 2011 4:43 AM
    Thursday, September 1, 2011 3:40 AM
  • I found the solution! The problem was with my connection string. In order to receive the right domain I needed to specify in the BlobEndpoint

    !

    • Marked as answer by Jonas Stawski Friday, September 2, 2011 9:03 PM
    Friday, September 2, 2011 9:03 PM

All replies

  • Hi Jonas,

    > Is this a bug or on purpose?

    It is on purpose. As custom domain needs a CName record in the domain provider. If there is something wrong when configuring the custom domain and if CloudBlob.Uri returns custom domain, we cannot ensure CloudBlob.Uri is a valid uri. To ensure CloudBlob.Uri is always valid, the default domain provided by Windows Azure is used.

    You can write your own code to replace CloudBlob.Uri with your custom domain. For example:

    public static string CustomDomainForBlob(string url)
    {
        string domain = "www.mydomain.com";
        string protocol = "http";
        string baseAddress = string.Format("{0}://{1}/", protocol, domain);
        return Regex.Replace(url, "^(http|https)://([^/]+)/", baseAddress);
    }

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Marked as answer by Jonas Stawski Thursday, September 1, 2011 4:43 AM
    Thursday, September 1, 2011 3:40 AM
  • Let me suggest a different way to do what Wenchao described:

    // instead of: var uri = blob.Uri;
    var uri = new UriBuilder(blob.Uri) { Host = "customdomain.com" }.Uri;
    
    That lets the Uri class do the work of parsing and replacing.

    Thursday, September 1, 2011 4:30 AM
  • Thank you guys for your response. I would like to suggest a new API for future SDKs. Keep the Uri for backward compatibility and add a new Uris property that returns an array of Uri, including the Windows Azure and any custom domain(s).

    If I modify the code the way you're proposing, I will need to maintain my code if my Domain changes in the future.

    With the new proposed property I am responsible for choosing the one I need, regardless of if it works or not.

    Thursday, September 1, 2011 4:43 AM
  • I found the solution! The problem was with my connection string. In order to receive the right domain I needed to specify in the BlobEndpoint

    !

    • Marked as answer by Jonas Stawski Friday, September 2, 2011 9:03 PM
    Friday, September 2, 2011 9:03 PM