托管 Blazor 在从 wwwroot 文件夹提供文件时遇到问题

问题描述 投票:0回答:1

我正在将 Stripe Website 集成到我托管的 .NET Core 应用程序中。具体来说,我需要针对 Apple Pay 验证我是网站所有者。 Stripe 网站上的说明告诉我下载文件并在 https://mywebsite.com/.well-known/apple-developer-merchantid-domain-association.

提供该文件。

我可以浏览到 https://mywebsite.com/favicon.jpg 并查看图标。但是当我尝试浏览到 https://mywebsite.com/.well-known/apple-developer-merchantid-domain-association 时,我得到了

我可以做什么来解决这个问题?我已经用谷歌搜索了一段时间了,但我发现没有任何东西对我有用。

我考虑从控制器端点返回文件,但路径将包含控制器名称,所以看起来会失败。有没有办法覆盖控制器路线?

.net-core static-files hosted-blazor-webassembly
1个回答
0
投票

我终于能够验证我的 Apple Pay 域名了。我在这里解释一下。

首先,这是针对https://stripe.com。他们希望我使用他们的 Stripe 仪表板验证我的域名,而不是直接向 Apple 验证。他们要求我下载一个没有扩展名的文件,并将该文件上传到我的 IIS Web 主机上的文件夹中。文件夹名称以句点开头。文件夹路径和文件名是

.well-known\apple-developer-merchantid-domain-association
。通常,在您的服务器项目上,如果您还没有 wwwroot 文件夹,则需要创建一个。然后在
wwwwroot
文件夹中创建 .wellknown 文件夹和文件。我在文件上设置了
Copy if Newer
,以便 VS 将该文件复制到我的输出文件夹中。 VS抱怨说:

Could not copy the file "C:\Users\user\source\repos\MyRepo\MySolution\Server\wwwroot\.well-known\apple-developer-merchantid-domain-association" to the destination file "bin\Debug\net8.0\wwwroot\.well-known\apple-developer-merchantid-domain-association", because the destination is a folder instead of a file. To copy the source file into a folder, consider using the DestinationFolder parameter instead of DestinationFiles.
。所以我手动将文件复制到那里并且成功了。当我发布我的解决方案时,它复制到正确的文件夹。但我仍然无法验证我的域名。

所以我采取了我认为的核选项。我认为这不是正确的方法,但它对我有用。我只是觉得这不是最好的方法。我将

.well-known
文件夹和文件移动到 wwwroot 之外名为
StaticFiles
的新文件夹中。然后我创建了一个名为 WellKnown 的控制器。

[AllowAnonymous]
[Route(".well-known")]
public class WellKnownController : ControllerBase
{
    public WellKnownController()
    {
        
    }

    [HttpGet]
    [Route("apple-developer-merchantid-domain-association")]
    public async Task<IActionResult> Get()
    {
        try
        {                
            byte[] content = await System.IO.File.ReadAllBytesAsync(@"StaticFiles\.well-known\apple-developer-merchantid-domain-association");
            
            return File(content, "text/plain", "apple-developer-merchantid-domain-association");
        }
        catch
        {
            return BadRequest();
        }
    }
}

注意控制器路由是.www-root,端点路由是文件名。

如果有人有更好的方法,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.