To add to the solutions provided by mogile_oli solution and Frédéric solution a little more configuration is required when using IIS configured for a Net.Core site.
TLDR: Remove aspNetCore
handler in the .well-known/web.config
and apply existing solution by either mogile_oli or Frédéric
One solution is to place the .well-known folder in the wwwroot folder as suggested here. However this either means making the apple-app-site-association
part of your .Net Core project or manually adding this after any publish update. You then make the MIME changes mentioned by mogile_oli or Frédéric
Another solution is to configure static files within the .Net Core app's startup class then the folder/files can live outside of the .Net Core project. This has the downside that this would require a rebuild of the application if you want to make any directory changes.
The solution we opted for doesn't require the .Net Core app to have any knowledge of the .well-known folder.
- If you don't have it already create a
.well-known
folder in the root of the IIS site folder.
- Add your
apple-app-site-association
(and if you doing the equivalent for android your assetlinks.json
file too).
- Add a web.config file to the `.well-known' folder with the following:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="application/json" />
<!-- Only required for assetlinks.json if your IIS version doesn't already have .json defined -->
<!-- <mimeMap fileExtension=".json" mimeType="application/json" /> -->
</staticContent>
<handlers>
<!-- Assumes that you have the handler in your root web.config called aspNetCore. Change to match your configuration -->
<remove name="aspNetCore" />
</handlers>
</system.webServer>
</configuration>
This code snippet stops the .Net Core app handling the .well-known folder and then we are free to configure it as per the previous solution by mogile_oli. (As an added bonus if you are adding assetlinks.json and using an older IIS version you need to add a mimeMap for .json files as well).
(Optional) The code snippet above has applied to the entire .well-known folder and as mentioned by Frédéric this can pose a security risk (especially if we have other files in the .well-known folder). We can transform the above to make use of Frédéric's location recommendation:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
<location path="apple-app-site-association">
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="application/json" />
</staticContent>
<handlers>
<remove name="aspNetCore" />
</handlers>
</system.webServer>
</location>
<!-- Only required for assetlinks.json -->
<location path="assetlinks.json">
<system.webServer>
<!-- Only required if your IIS version doesn't already have .json defined -->
<!-- <staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent> -->
<handlers>
<remove name="aspNetCore" />
</handlers>
</system.webServer>
</location>
</configuration>
Hope this helps anyone in a similar situation as it took us a lot of trial and error.