【问题标题】:Static files outside the wwwroot for .netcore app.netcore 应用程序的 wwwroot 之外的静态文件
【发布时间】:2016-11-19 06:45:20
【问题描述】:

我在我的@home 网络服务器上使用https://github.com/ebekker/ACMESharp 作为我的 SSL(它是免费的!:O)。它非常手动,但在 wiki 上注意到它提到了另一个项目 https://github.com/Lone-Coder/letsencrypt-win-simple,这是一个用于自动申请、下载和安装 SSL 证书到 Web 服务器的 GUI。

GUI 用来验证域是否属于您的方法是通过在[webroot]/.well-known/[randomFile] 中创建一个随机命名的文件,其中包含随机文本字符串,不带扩展名。在此 [webroot] 上运行 .dotnetcore 应用程序时,我无法提供该文件,即使按照说明更改 IIS 下的“处理程序映射”也是如此。

似乎我可以通过在 [webRoot]/wwwroot/[whatever] 直接导航到文件来提供文件 - 那么为什么我不能在 [webroot]/.well-known/[randomFile] 中呢?

有人知道解决这个问题的方法吗?我可以删除 .netcore 应用程序,然后运行 ​​SSL 证书安装,但此安装需要每 2-3 个月进行一次,由于它是手动的,我更愿意弄清楚如何以正确的方式进行。

【问题讨论】:

    标签: ssl iis asp.net-core static-files staticfilehandler


    【解决方案1】:

    我在这里找到了我需要的信息:https://docs.asp.net/en/latest/fundamentals/static-files.html

    基本上在我的 Statup.cs 中我需要更改它:

            // allows for the direct browsing of files within the wwwroot folder
            app.UseStaticFiles();
    
            // MVC routes
            app.UseMvc(routes => 
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
    

    到这里:

            // allows for the direct browsing of files within the wwwroot folder
            app.UseStaticFiles();
    
            // Allow static files within the .well-known directory to allow for automatic SSL renewal
            app.UseStaticFiles(new StaticFileOptions()
            {
                ServeUnknownFileTypes = true, // this was needed as IIS would not serve extensionless URLs from the directory without it
                FileProvider = new PhysicalFileProvider(
                        Path.Combine(Directory.GetCurrentDirectory(), @".well-known")),
                RequestPath = new PathString("/.well-known")
            });
    
            // MVC routes
            app.UseMvc(routes => 
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
    

    编辑 - 请注意,此目录“.well-known”仅在 Web 服务器上创建,当我在本地再次开始开发时,由于“.well-known”目录不存在而出现错误。所以现在我的项目中只有一个空目录,但至少我的 SSL 更新是自动化的! :D

    【讨论】:

    • 你拯救了我的一天。谢谢
    猜你喜欢
    • 2016-04-19
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    相关资源
    最近更新 更多