如何从 Asp .Net Core 提供目录名称中带有句点的静态文件
How to serve static file from Asp .Net Core with period in directory name
我目前正在尝试将 Apple Pay 与网站相关联。为了验证域,Apple Pay 要求网站能够提供位于 https://websiteurl/.well-known/apple-developer-merchantid-domain-association
.
的特定静态文件
我目前无法让我的网站提供此静态文件。我可以提供其他静态文件,但不能提供这个特定文件。我想问题与目录名称中的句点有关。我尝试遵循 的建议,但没有成功。
我的 wwwroot
目录结构如下所示:
wwwroot
.well-known
apple-developer-merchantid-domain-association
web.config
App_Data
Content
css
js
app.js
lib
.well-known -> web.config 的内容是:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
我相信这就是 中接受的答案中描述的内容。
但是,当我尝试访问 https://websiteurl/.well-known/apple-developer-merchantid-domain-association 时,出现 HTTP 404 错误。
我验证了我可以成功访问静态文件,因为 https://websiteurl/js/app.js 工作成功。
我也试过把web.config
直接放在wwwroot
下面
不确定我做错了什么。有什么建议吗?
尝试文件服务器:
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.UseFileServer(new FileServerOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "MyStaticFiles")),
RequestPath = "/wwwroot",
EnableDirectoryBrowsing = true
});
}
原来问题不是目录名中的句点,而是文件缺少扩展名。 Startup.cs 中的以下代码解决了问题:
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new physicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/.well-known")),
RequestPath = "/.well-known",
ServeUnknownFileTypes = true,
DefaultContentType = "text/plain"
});
我目前正在尝试将 Apple Pay 与网站相关联。为了验证域,Apple Pay 要求网站能够提供位于 https://websiteurl/.well-known/apple-developer-merchantid-domain-association
.
我目前无法让我的网站提供此静态文件。我可以提供其他静态文件,但不能提供这个特定文件。我想问题与目录名称中的句点有关。我尝试遵循
我的 wwwroot
目录结构如下所示:
wwwroot
.well-known
apple-developer-merchantid-domain-association
web.config
App_Data
Content
css
js
app.js
lib
.well-known -> web.config 的内容是:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
我相信这就是
但是,当我尝试访问 https://websiteurl/.well-known/apple-developer-merchantid-domain-association 时,出现 HTTP 404 错误。
我验证了我可以成功访问静态文件,因为 https://websiteurl/js/app.js 工作成功。
我也试过把web.config
直接放在wwwroot
不确定我做错了什么。有什么建议吗?
尝试文件服务器:
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.UseFileServer(new FileServerOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "MyStaticFiles")),
RequestPath = "/wwwroot",
EnableDirectoryBrowsing = true
});
}
原来问题不是目录名中的句点,而是文件缺少扩展名。 Startup.cs 中的以下代码解决了问题:
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new physicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/.well-known")),
RequestPath = "/.well-known",
ServeUnknownFileTypes = true,
DefaultContentType = "text/plain"
});