简体   繁体   English

用于.netcore应用程序的wwwroot之外的静态文件

[英]Static files outside the wwwroot for .netcore app

I'm using https://github.com/ebekker/ACMESharp for my SSL at my @home web-server (it's free! :O). 我在我的@home网络服务器上使用https://github.com/ebekker/ACMESharp作为我的SSL(它是免费的!:O)。 It was pretty manual, but noticed on the wiki it mentioned another project at https://github.com/Lone-Coder/letsencrypt-win-simple which was a GUI for the automation of applying for, downloading, and installing of your SSL cert to your web-server. 这是非常手动的,但在维基上注意到它提到了https://github.com/Lone-Coder/letsencrypt-win-simple上的另一个项目,这是一个用于自动申请,下载和安装SSL的GUI证书到您的网络服务器。

The method the GUI uses to validate the domain is yours, is by created a randomly named file with a random string of text within [webroot]/.well-known/[randomFile] w/o an extension. GUI用于验证域的方法是由你自己创建的,随机命名的文件是在[webroot]/.well-known/[randomFile]内的随机文本字符串,没有扩展名。 With the .dotnetcore application running on this [webroot], I am unable to serve the file, even after following the instructions for changing "Handler Mappings" under IIS. 使用.dotnetcore应用程序在此[webroot]上运行,即使遵循IIS下更改“处理程序映射”的说明,我也无法提供该文件。

It seems like I can serve files by navigating directly to them at [webRoot]/wwwroot/[whatever] - so why can't I in [webroot]/.well-known/[randomFile] ? 看来我可以通过直接导航到[webRoot]/wwwroot/[whatever]来提供文件 - 所以为什么我不能在[webroot]/.well-known/[randomFile]

Anyone know a way around this? 有人知道解决这个问题吗? I can delete the .netcore app, then run the SSL cert installation, but this installation needs to happen every 2-3 months, and since it's manual I'd prefer to figure out how to do it the right way. 我可以删除.netcore应用程序,然后运行SSL证书安装,但这个安装需要每2-3个月进行一次,因为它是手动的,我更愿意弄清楚如何以正确的方式做到这一点。

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

Basically in my Statup.cs I needed to change this: 基本上在我的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?}");
        });

to this: 对此:

        // 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?}");
        });

EDIT - Note that this directory ".well-known" was created only on the web server, when I started developing again locally, I was getting errors because the ".well-known" directory did not exist. 编辑 - 请注意,此目录“.well-known”仅在Web服务器上创建,当我在本地再次开始开发时,我收到错误,因为“.well-known”目录不存在。 So now I just have an empty directory in my project, but at least my SSL renewal is automated! 所以现在我的项目中只有一个空目录,但至少我的SSL更新是自动化的! :D :d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM