Serving a file with no extension from an Azure Web App

Guillermo Rodriguez 0 Reputation points
2023-11-10T17:15:00.92+00:00

I'm trying to serve a text file that has no extension from within a Web App.

The file is located in the .well-known folder. Other files (with json extension) from the .well-known folder are accessible, but when I try to access the file with no extension, the app redirects to the home page.

I modified the web.config and added support for 2 mime types with no positive results.

The content of the web.config as it is now is listed below:

?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\Slp.Web.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
<staticContent> 
          <mimeMap fileExtension=".json" mimeType="application/json" />
          <mimeMap fileExtension="." mimeType="application/json" />
</staticContent>
    </system.webServer>
  </location>
</configuration>
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,005 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 18,646 Reputation points
    2023-11-14T02:58:13.5066667+00:00

    Hi @Guillermo Rodriguez , thanks for the question.

    To serve a file with no extension from within a Web App on Azure, you might encounter issues because Azure Web Apps are configured to serve known file types by default. To work around this, you can try adding a custom MIME type for files with no extension in the web.config file.

    Here's an example of how you can modify your web.config to include a custom MIME type for files with no extension:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <location path="." inheritInChildApplications="false">
        <system.webServer>
          <handlers>
            <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
          </handlers>
          <aspNetCore processPath="dotnet" arguments=".\Slp.Web.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
          <staticContent>
            <remove fileExtension="." />
            <mimeMap fileExtension="." mimeType="text/plain" />
            <mimeMap fileExtension=".json" mimeType="application/json" />
          </staticContent>
        </system.webServer>
      </location>
    </configuration>
    
    

    Also, ,if you’re using ASP.NET Core, you might need to configure the static files middleware to serve files without an extension. Ensure that the file is located in a folder that is configured to serve static files. In ASP.NET Core, this is typically the /wwwroot folder

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.