简体   繁体   中英

ASP.Net Core Custom Absolute Root Path

In an ASP.Net Core webapplication pages are searched from certain paths. 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. The page can thus be accessed with the path "/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 . 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.

How can I change this behavior so that ASP.Net Core does not interfere in this manner? 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. 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.

I recommend using the relative path "~"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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