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

Gur*_*528 1 c# .net-core kestrel-http-server lets-encrypt asp.net-core

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

我在使用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-services)进行认证

我已经看到了,但这是一个已知的文件名,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>
Run Code Online (Sandbox Code Playgroud)

这是整个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>
Run Code Online (Sandbox Code Playgroud)

这是添加到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
});
Run Code Online (Sandbox Code Playgroud)

moj*_*imi 7

对我来说,它的工作原理是这样的:

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,
     });
Run Code Online (Sandbox Code Playgroud)

并将以下几行放在里面 <system.webServer>

 <staticContent>
      <mimeMap fileExtension=".*" mimeType="text/plain" />
 </staticContent>
Run Code Online (Sandbox Code Playgroud)


Syn*_*der 5

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

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

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

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

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


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


归档时间:

查看次数:

727 次

最近记录:

6 年,7 月 前