Add. Well known in asp.net core

I want to have a directory .well-known

in my root for an extension renewal.

I added a route to .well-known

like this:

 app.UseStaticFiles(new StaticFileOptions
        {
            FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @".well-known")),
            RequestPath = new PathString("/.well-known"),
            ServeUnknownFileTypes = true // serve extensionless file
        });

      

I added a directive inside my wwwroot called .well-known

, but it never gets copied to the output when posted .

I tried adding a file to it and also editing csproj:

  <ItemGroup>
    <Content Include="wwwroot\.well-known\" />
  </ItemGroup>

      

Every time I publish, I have to manually create a directory. How can I automatically add it to wwwroot?

+3


source to share


3 answers


I tried adding a file to it and also editing csproj:

<ItemGroup>
  <Content Include="wwwroot\.well-known\" />
</ItemGroup>

      

You cannot copy folders via Content, only files. You must change it to



<ItemGroup>
  <Content Include="wwwroot\**">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Content>
<ItemGroup>

      

and as mentioned in the comments you need to put an empty dummy file inside.

+6


source


You can add below code to file MyProject.csproj



  <ItemGroup>
    <Content Include=".well-known\acme-challenge\**">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

      

+1


source


Another approach is to create a controller - if you have complex rules - or the file is domain specific (as is the case for certain types of validation tokens).

public class WellKnownFileController : Controller
{
    public WellKnownFileController()
    {

    }

    [Route(".well-known/apple-developer-merchantid-domain-association")]
    public ContentResult AppleMerchantIDDomainAssociation()
    {
        switch (Request.Host.Host)
        {
            case "www2.example.com":
                return new ContentResult
                {
                    Content = @"7B227073323935343637",
                    ContentType = "text/text"
                };

            default:
                throw new Exception("Unregistered domain!");
        }
    }
}

      

Then you can just push .well-known/apple-developer-merchantid-domain-association

and get that controller.

Of course, you can download a file from disk or whatever you need to do - or have pass-through access.

0


source







All Articles