asp.net-core - 如何在目录名称中使用句点从 Asp .Net Core 提供静态文件

标签 asp.net-core applepay

我目前正在尝试将 Apple Pay 与网站相关联。为了验证域,Apple Pay 要求网站能够提供位于 https://websiteurl/.well-known/apple-developer-merchantid-domain-association 的特定静态文件。

我目前无法让我的网站提供这个静态文件。我可以提供其他静态文件,但不能提供这个特定文件。我想问题与目录名称中的句点有关。我尝试遵循 this question 的建议但没有成功。

我的 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>

我相信这就是 this question 中接受的答案中所描述的内容.

但是,当我尝试访问 https://websiteurl/.well-known/apple-developer-merchantid-domain-association 时,我收到 HTTP 404 错误。

我验证了我可以成功访问静态文件,因为 https://websiteurl/js/app.js成功运行。

我也试过把 web.config 直接放在 wwwroot

不确定我做错了什么。有什么建议吗?

最佳答案

原来问题不是目录名中的句点,而是文件缺少扩展名。 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"
     });

关于asp.net-core - 如何在目录名称中使用句点从 Asp .Net Core 提供静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61127821/

相关文章:

c# - 在 .Net Core 中使用弱事件

asp.net - IIS 仅将域的 http 重定向到 https

android - 使用 Android 7.0 或更高版本从 iPhone Suica App 读取 NFC 数据时出现问题

php - IOS收据验证错误21002

ios - Apple Pay 与 React Native

objective-c - PKAddPassPaymentRequest 无法发送请求

plugins - Apple/Android 在 nativeScript 中支付

c# - 带有 AsyncLocal 与 Scope 服务的单例

asp.net-core - 从 ASP.NET Core 2.1 应用程序中删除 "Server" header

asp.net - .Net Core 2.0 - 获取 AAD 访问 token 以与 Microsoft Graph 一起使用