[英]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.