I want to have a .well-known
directory in my root for letsencrypt renewals.
I have added a route to .well-known
like so:
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 direcotry inside my wwwroot called .well-known
but it never gets copied to the output when I publish.
I tried adding a file to it and also edit csproj:
<ItemGroup>
<Content Include="wwwroot\.well-known\" />
</ItemGroup>
Every time I publish I have to manually create the directory. How do I get it automatically added to the wwwroot?
I tried adding a file to it and also edit csproj:
<ItemGroup> <Content Include="wwwroot\.well-known\" /> </ItemGroup>
You can't copy over folders via Content, only files. You have to change it to
<ItemGroup>
<Content Include="wwwroot\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<ItemGroup>
and like mentioned in the comments, you need to put an empty dummy file inside.
Another approach is to make a controller - if you have complex rules - or the file varies by domain (as it does for certain types of verification 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!");
}
}
}
You can then just hit .well-known/apple-developer-merchantid-domain-association
and get this controller.
Of course you can load the file from disk or whatever you need to do - or have a passthrough.
you can add the below code to the MyProject.csproj
file
<ItemGroup>
<Content Include=".well-known\acme-challenge\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With