.net-corestatic-fileshosted-blazor-webassembly

Hosted Blazor having trouble serving file from wwwroot folder


I am integrating Stripe Website into my hosted .NET Core app. Specifically, I need to verify for Apple Pay that I am the site owner. The instructions on the Stripe website tell me to download a file and make it available at https://mywebsite.com/.well-known/apple-developer-merchantid-domain-association.

Instructions From Website

File Manager On Web Host

Visual Studio Folder

I can browse to https://mywebsite.com/favicon.jpg and see the icon. But when I try to browse to https://mywebsite.com/.well-known/apple-developer-merchantid-domain-association, I get

Website Results

What can I do to solve this issue? I have been Googling for a while now, and nothing I have found seem to work for me.

I considered returning the file from a controller endpoint, but the path would include the controller name, so it seems like that would fail. Is there a way to override the controller route?


Solution

  • I was finally able to verify my domain for Apple Pay. I'll explain here.

    First of all, this is for https://stripe.com. They want me to verify my domain using their Stripe dashboard rather than verifying directly with Apple. They ask me to download a file, which doesn't have an extension and upload the file to a folder on my IIS webhost. The folder name starts with a period. The folder path and filename are .well-known\apple-developer-merchantid-domain-association. Normally on your server project, you would create a wwwroot folder if you don't have one already. Then create the .well-known folder and file inside the wwwwroot folder. I set Copy if Newer on the file so that VS will copy the file to my Output folder. VS complained that:

    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.. So I copied the file there manually and it worked out. When I published my solution, it copied to the correct folder. But I still could not verify my domain.

    So I took what I consider to be the nuclear option. I don't think this is the right way to do it, but it worked for me. I just don't feel like this is the best way to do it. I moved the .well-known folder and file to a new folder named StaticFiles outside of wwwroot. Then I created a controller named 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();
            }
        }
    }
    

    Notice the controller route is .www-root and the end-point route is the filename.

    If someone has a better way to do it, please let me know.