Tushar Kesare
Tushar Kesare

Reputation: 790

Getting mapped custom domain url in Azure

My azure web application (myapp.azurewebsites.net) is mapped to a custom domain (client1.mycompany.com).

I will be mapping it to some more custom domains (client2.mycompany.com, client3.mycompany.com etc.) one per each client.

In web application I am using

HttpContext.Current.Request.Url.Host 

to get custom domain address which is accessing the application. But it is sometimes returning myapp.azurewebsites.net instead of custom domain.

Any idea how I can custom domain url in Azure in reliable way?

Upvotes: 2

Views: 1880

Answers (2)

RuslanY
RuslanY

Reputation: 894

As Admir said in his answer the default *.azurewebsites.net binding cannot be removed, but it is very easy to prevent users from using this domain name for your site.

<rewrite>
<rules>
<rule name="Canonical Host Name" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="client1.mycompany.com" negate="true" />
    </conditions>
    <action type="Redirect" url="http://client1.mycompany.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>

Upvotes: 1

Admir Tuzović
Admir Tuzović

Reputation: 11177

*.azurewebsites.net is not removable which means it is out of your control if someone will access your website through that DNS binding, which explains why you get that when you attempt to inspect HttpContext.Current.Request.Url.Host.

Only thing you can do is to choose to ignore requests coming directly to that binding, by redirecting user to:

  • Custom page (i.e. 404)
  • Some default custom domain

Upvotes: 0

Related Questions