Search code examples
asp.net-mvc-5

Configure well-known folder in MVC 5 Web App?


I'm having problems creating and accessing a well-known folder in an MVC 5 Web App. I need the folder to house some documents for iOS and Android mobile apps.

First, I add a well-known folder to my MVC 5 Web App. I could not add a .well-known folder. Since I could not add the "." in front of the folder, I added a virtual directory using the Azure Portal.

enter image description here

This seems to work, but When I try to access the files using https://portal.mydomain.com/.well-known/apple-app-site-association or this https://portal.mydomain.com/.well-known/assetlinks.json, I get the following message.

"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

When I try to access just the directory using https://portal.mydomain.com/.well-known/ I get the following message.

"You do not have permission to view this directory or page."

Finally, I added this to my web.config in order to handle the lack of a file extension on the apple-app-site-association file.

  <staticContent>
    <mimeMap fileExtension="." mimeType="application/octet-stream" />
  </staticContent>

Any help is much appreciated. Thanks!


Solution

  • I added a new web.config file to my well-known folder and configured it like so. I can now access both files. This is a new web.config and has nothing to do with the web.config in the root directory. Using this config, the apple-app-site-association downloads a file when I access it using a web browser. The assetlinks.json file displays in the web page, so they behave differently.

    <?xml version="1.0" encoding="UTF-8"?>
     <configuration>
      <system.webServer>
       <staticContent>
        <mimeMap fileExtension="." mimeType="application/octet-stream" />
        <mimeMap fileExtension=".json" mimeType="application/json" />
       </staticContent>
      </system.webServer>
     </configuration>
    

    I commented out this entry in my root directory web.config because I did not need it.

    <staticContent>
     <mimeMap fileExtension="." mimeType="application/octet-stream" />
    </staticContent>
    

    If not work above solution then add rule Create a rule in the "web.config" file, which will provide the Json value when the Applebot robot crawl your site for the apple association

    <rewrite>
        <rules>
            <rule name="apple_json_file">
                    <match url="^apple-app-site-association" />
                    <action type="Rewrite" url="apple-app-site-association.json" />
                </rule>
        </rules>
    </rewrite>
    

    Add this section in system.webServer