share my recent experiences on get let'sencrypt working with nop

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Last Friday I started to get a free SSL for my test website (Nop 4.0), and 'let's encrypt' is my choice. There are many tutorials in the internet, so I won't repeat them but just share something related to Nop.

There is a good tool named 'letsencrypt-win-simple'. Run its latest version as an admin, and it provides clear instructions. The only thing to note is that to verify that I actually own the domain, it will create a challenge file (a json file, but without any extension, which is the trouble maker) inside the \.well-known\acme-challenge folder. To make the verification working, this file should be accessible by the ssl provider.

The initial trail failed, and letsencrypt-win-simple reminded me that it couldn't access the challenge file (I can't in my browser neither) possibly due to IIS's default setting of not serving extensionless files. Please don't waste time here - actually as Nop is using extensionless url so anything we do with IIS won't be able to serve the challenge file. What we need to do is to tell nop to return the content of the amazing extentionless file. As I am quite new to nop, I am not sure how you guys handle this but what I did are:
(1) create a controller which simply read the challenge file and return its content
(2) register a router

I hope this saves your time, and please let me know the better solutions:)

//------my crude code, if you need it-----
(1)the new controller
[HttpsRequirement(SslRequirement.No)]
    public partial class LetsencryptController : BasePublicController
  {      
        public virtual string Index(string fileName)
        {
            var content = "File not found";
            if (!string.IsNullOrEmpty(fileName))
            {
                var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", ".well-known", "acme-challenge", fileName);
                FileInfo fi = new FileInfo(filePath);
                if (!fi.Exists)
                {
                    filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,  ".well-known", "acme-challenge", fileName);
                    fi = new FileInfo(filePath);
                }
                    if (fi.Exists)
                {
                    content = System.IO.File.ReadAllText(filePath);
                }                  
            }
            return content;
        }      
        
    }

(2)in RouteProvider.cs
//Letsencrypt
            routeBuilder.MapLocalizedRoute("Letsencrypt", ".well-known/acme-challenge/{fileName}/",
                new { controller = "Letsencrypt", action = "Index" });
4 years ago
Thanks, this worked for me on 4.20
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.