Search code examples
c#asp.net-core.net-corelets-encryptkestrel-http-server

ASP.NET Core 2.0 - Serving files with no extension


I'm trying too set up Let's Encrypt on my site. I have found a bunch of solutions online, unfortunately none have worked for me.

I'm on Debian 8.7 with Apache 2 and .NET Core 2.0.

I've tried placing a web.config (and a few variations of it) in the .well-known/acme-challenge folder to no luck. I've triedthe solutions at these links (mainly adding a web.config and adding some code):

https://github.com/ebekker/ACMESharp/issues/15
Set web.config for letsencrypt - Certify with Asp.NET Core and Angular 2 (Javascript-services)

I have seen this but it's for a known file name, LE gives random file names so I don't know how to implement it: asp.net core - How to serve static file with no extension

I know it's not an issue with me getting the URL wrong as if I add an extension (for example .t) to the file and then add that to the URL the site is correctly returning the file.

Here's the web.config in acme-challenge:

<?xml version = "1.0" encoding="UTF-8"?>
 <configuration>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".*" mimeType="text/plain" />
        </staticContent>
        <handlers>
            <clear />
            <add name="StaticFile" path="*" verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Read" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
        </handlers>
     </system.webServer>
 </configuration>

Here's the overall web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\my.site.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>

Here's the code added to Configure():

app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider("/var/aspnet/miadola/wwwroot/.well-known"),
    RequestPath = new PathString("/var/aspnet/miadola/wwwroot/.well-known"),
    ServeUnknownFileTypes = true // serve extensionless files
});

Solution

  • You code looks good, except for 1 line.

    app.UseStaticFiles(new StaticFileOptions {
        FileProvider = new PhysicalFileProvider("/var/aspnet/miadola/wwwroot/.well-known"),
        RequestPath = new PathString("/.well-known"),
        ServeUnknownFileTypes = true // serve extensionless files
    });
    

    Spotted the difference? The line is the RequestPath. That line is what you enter in the browser after the domain.

    So currently your solution points works when you go to:

    www.example.com/var/aspnet/miadola/wwwroot/.well-known


    Also there is no need for the web.config files, those are for when you are running under IIS (windows).