简体   繁体   English

ASP.Net Core 自定义绝对根路径

[英]ASP.Net Core Custom Absolute Root Path

In an ASP.Net Core webapplication pages are searched from certain paths.在 ASP.Net Core Web 应用程序页面中从特定路径搜索。 For example, the Index page in a Razor Page application is located in the folder "Pages" (by default), which is relative to the application root folder.例如,Razor Page 应用程序中的 Index 页面位于文件夹“Pages”(默认情况下)中,该文件夹相对于应用程序根文件夹。 The page can thus be accessed with the path "/Index".因此可以使用路径“/Index”访问该页面。

However, I would want to access the pages by a true absolute path.但是,我想通过真正的绝对路径访问页面。 Which means that the entire path would have to be specified to access the view.这意味着必须指定整个路径才能访问视图。 On Windows the complete path could be C:/Project/Pages/Index.cshtml .在 Windows 上,完整路径可能是C:/Project/Pages/Index.cshtml But ASP.Net Core can not handle this by default, becuase this path would be resolved to: /Pages/C:/Project/Pages/Index.cshtml (relative to the application root, which is wrong.但是 ASP.Net Core 默认不能处理这个,因为这个路径会被解析为:/ Pages /C: /Project/Pages/Index.cshtml (相对于应用程序根,这是错误的。

How can I change this behavior so that ASP.Net Core does not interfere in this manner?如何更改此行为,以便 ASP.Net Core 不会以这种方式进行干扰? The reason I want to change this behavior is that on Linux when a path starts with "/", then it points to the root of the filesystem and not to the root of an application.我想改变这种行为的原因是,在 Linux 上,当路径以“/”开头时,它指向文件系统的根目录而不是应用程序的根目录。 I want the same behavior everywhere.我希望到处都有相同的行为。

Note: I do not want to use the tilde character ("~") either.注意:我也不想使用波浪号(“~”)。

Thanks!谢谢!

It is really difficult because when deploying the application are *.dll files and then it will not find the file in that path.这真的很困难,因为在部署应用程序时是 *.dll 文件,然后它不会在该路径中找到该文件。

I recommend using the relative path "~"我建议使用相对路径“~”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM