Gue*_*lla 4 c# lets-encrypt asp.net-core
我希望.well-known在我的root中有一个目录用于letsencrypt续订.
我添加了一条路线.well-known:
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @".well-known")),
RequestPath = new PathString("/.well-known"),
ServeUnknownFileTypes = true // serve extensionless file
});
Run Code Online (Sandbox Code Playgroud)
我在我的wwwroot中添加了一个direcotry,.well-known但是当我发布时它永远不会被复制到输出中.
我尝试添加一个文件,并编辑csproj:
<ItemGroup>
<Content Include="wwwroot\.well-known\" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
每次我发布我都要手动创建目录.如何将其自动添加到wwwroot?
Sim*_*ver 11
另一种方法是创建一个控制器 - 如果您有复杂的规则 - 或者文件因域而异(就像某些类型的验证令牌一样)。
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!");
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后你就可以点击.well-known/apple-developer-merchantid-domain-association并获取这个控制器。
当然,您可以从磁盘加载文件或执行任何您需要执行的操作 - 或者进行直通。
我尝试添加一个文件,并编辑csproj:
Run Code Online (Sandbox Code Playgroud)<ItemGroup> <Content Include="wwwroot\.well-known\" /> </ItemGroup>
您无法通过内容复制文件夹,只能复制文件.你必须把它改成
<ItemGroup>
<Content Include="wwwroot\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<ItemGroup>
Run Code Online (Sandbox Code Playgroud)
并且像评论中提到的那样,你需要在里面放一个空的虚拟文件.
小智 6
这对我有用......
在 csproj 文件中:
<ItemGroup>
<Content Include="wwwroot\.well-known\**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
在 Startup.cs 中
app.UseStaticFiles(); // <-- don't forget this
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot/.well-known")),
RequestPath = new PathString("/.well-known"),
ServeUnknownFileTypes = true
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2133 次 |
| 最近记录: |