Getting mapped custom domain url in Azure

不想你离开。 提交于 2020-01-16 00:46:22

问题


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?


回答1:


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>



回答2:


*.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


来源:https://stackoverflow.com/questions/31914361/getting-mapped-custom-domain-url-in-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!