Hi @Louis Chan,
After investigating the issue and I found we can implement this feature by using rewrite rules.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<rewrite>
<!--<rules>-->
<!-- Block access to Azure default domain names -->
<!--<rule name="Block Azure Default Domain" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^your_app_name\.azurewebsites\.net$" />
</conditions>
<action type="CustomResponse" statusCode="404" statusReason="Not Found" statusDescription="This page is not available." />
</rule>
</rules>-->
<outboundRules>
<!-- Add X-Robots-Tag header -->
<rule name="Noindex Azure Default Domain" preCondition="ResponseIsHtml">
<match serverVariable="RESPONSE_X_ROBOTS_TAG" pattern=".*" />
<conditions>
<!-- if request from default domain -->
<add input="{HTTP_HOST}" pattern="^webapplication220240628111356\.azurewebsites\.net$" />
</conditions>
<!-- set X-Robots-Tag -->
<action type="Rewrite" value="noindex, nofollow" />
</rule>
<!-- Precondition to check if response is HTML -->
<preConditions>
<preCondition name="ResponseIsHtml">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\WebApplication1.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Jason