Set web.config for letsencrypt - Certify with Asp.NET Core and Angular 2 (Javascript-services)

对着背影说爱祢 提交于 2019-11-30 14:11:50

Put this in the .\.well-known\acme-challenge\Web.Config file just next to the Lets Encrypt DNS verification file(s). No need to change the Web.Config you already have. All it does it tell IIS to cough up files without extension in the directory where this Web.Config resides with mime type text/plain as Lets Encrypt expects that.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension="." mimeType="text/plain" />
        </staticContent>
        <handlers>
            <clear />
            <add name="StaticFile" path="*" verb="GET" modules="StaticFileModule" resourceType="Either" />
        </handlers>
    </system.webServer>
</configuration>

The problem I ran into with the default web.config in the acme-challenge folder was that the applicationhost.config contained:

<section name="handlers" overrideModeDefault="Deny" />

The handlers section in the acme-challenge web.config therefore was not allowed with the result that the challenge failed. In this case the solutions were: Change applicationhost.config line to:

<section name="handlers" overrideModeDefault="Allow" />

Or ... Remove the handlers setting from the web.config in acme-challenge folder.

In my case, the problem was I forgot to remove App_Offline.htm while issuing the request. After removing it, the problem disappeared.

I had the same problem. In my case, I also had to add this code into my Startup.cs.

Also, be sure to add the .well-known directory. It is a hidden folder - so use the name, ".well-known." (the trailing dot will disappear). Windows will not allow a new hidden folder without the beginning and trailing dot.

using Microsoft.Extensions.FileProviders;
using System.IO;
using Microsoft.AspNetCore.Http;
public class Startup
{
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseStaticFiles();
        app.UseStaticFiles(new StaticFileOptions
        {
            FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @".well-known")),
            RequestPath = new PathString("/.well-known"),
            ServeUnknownFileTypes = true // serve extensionless files
        });
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!