繁体   English   中英

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

[英]ASP.NET Core 2.0 - Serving files with no extension

我也尝试在我的网站上设置“让我们加密”。 我在网上找到了很多解决方案,很遗憾,没有一个对我有用。

我在使用Apache 2和.NET Core 2.0的Debian 8.7。

我尝试将web.config(及其一些变体)放置在.well-known / acme-challenge文件夹中,以免碰运气。 我在这些链接上尝试过解决方案(主要是添加web.config并添加一些代码):

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

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

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

这是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>

这是整个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>

这是添加到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
});

您的代码看起来不错,除了1行。

app.UseStaticFiles(new StaticFileOptions {
    FileProvider = new PhysicalFileProvider("/var/aspnet/miadola/wwwroot/.well-known"),
    RequestPath = new PathString("/.well-known"),
    ServeUnknownFileTypes = true // serve extensionless files
});

发现差异? 该行是RequestPath。 该行是您在浏览器中域之后输入的内容。

因此,当您转到以下位置时,当前您的解决方案点有效:

www.example.com/var/aspnet/miadola/wwwroot/.well-known


另外,也不需要web.config文件,这些文件是在IIS(Windows)下运行时的文件。

对我来说,它的工作原理如下:

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,
     });

并将以下行放入<system.webServer>

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

暂无
暂无

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

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