简体   繁体   English

ASP.NET Core 2.0-提供没有扩展名的文件

[英]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. 我在使用Apache 2和.NET Core 2.0的Debian 8.7。

I've tried placing a web.config (and a few variations of it) in the .well-known/acme-challenge folder to no luck. 我尝试将web.config(及其一些变体)放置在.well-known / acme-challenge文件夹中,以免碰运气。 I've triedthe solutions at these links (mainly adding a web.config and adding some code): 我在这些链接上尝试过解决方案(主要是添加web.config并添加一些代码):

https://github.com/ebekker/ACMESharp/issues/15 https://github.com/ebekker/ACMESharp/issues/15
Set web.config for letsencrypt - Certify with Asp.NET Core and Angular 2 (Javascript-services) 为letencrypt设置web.config-使用Asp.NET Core和Angular 2进行验证(Javascript服务)

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 我已经看到了,但这是一个已知的文件名,LE提供了随机文件名,因此我不知道如何实现它: asp.net core-如何在不扩展名的情况下提供静态文件

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. 我知道我得到正确的URL并不是问题,就好像我将扩展名(例如.t)添加到文件中,然后将其添加到URL中一样,站点可以正确地返回文件。

Here's the web.config in acme-challenge: 这是acme-challenge中的web.config:

<?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: 这是整个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(): 这是添加到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
});

You code looks good, except for 1 line. 您的代码看起来不错,除了1行。

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. 该行是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 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). 另外,也不需要web.config文件,这些文件是在IIS(Windows)下运行时的文件。

For me it worked by something like this: 对我来说,它的工作原理如下:

app.UseStaticFiles(); // For the wwwroot folder
app.UseStaticFiles(new StaticFileOptions    //For the '.well-known' folder
     {
          FileProvider = new PhysicalFileProvider(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/.well-known")),
          RequestPath = "/.well-known",
          ServeUnknownFileTypes = true,
     });

and also putting following lines inside <system.webServer> 并将以下行放入<system.webServer>

 <staticContent>
      <mimeMap fileExtension=".*" mimeType="text/plain" />
 </staticContent>

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

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