我创建了一个自定义文件夹,用于存储文档,并在这样的Startup.cs中将其声明为静态文件。
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(RepositoryManager.GetBasePath()),
RequestPath = RepositoryManager.GetRequestPath()
});
public static string GetBasePath()
{
var relativePath = @"../../DS/DS.Repository/Repositories";
var absolutePath = Path.GetFullPath(relativePath);
return absolutePath;
}
public static string GetRequestPath()
{
return "/Repositories";
}
当我保存文档时,生成的链接如下:
〜/存储库/样本/acc_bcc.PNG
但是,当我从“文档”区域中的ui访问它时:
"data": function (data, type, row, meta) {
var url = "~/Repositories/Sample/acc_bcc.PNG";
return "<a href='" + url + "'>" + data.Name+"</i></a>"
}, "name": "Name"
URL最终看起来像这样:
https://localhost:44325/Documents/~/Repositories/Sample/acc_bcc.PNG
如何修复它,以便相对路径链接到我的文件?