The simplest question for which I can't find an answer.
I have an asp.net core 2.1 MVC application with Razor.
Application widely uses ~/path
syntax.
Everything works great if application runs from domain root (for example, from http://localhost:5000/)
But when I run application at non-root (for example, http://localhost:5000/app) the Razor still uses root (/
) as base path.
Question: how to configure this? How to specify base path for Razor's ~/
? There must be an environment variable for it :)
PS: Application run in docker behind the reverse proxy.
To do this, you can add a public property of a suitable data type to the page model class and a parameter to the OnGet() method with the same name and data type as the route parameter: public class PostModel : PageModel. { public string Title { get; set; }
The extension method WithRazorPagesRoot is defined in the class named MvcRazorPagesMvcBuilderExtensions and it assigns the new path to the “RootDirectory” property. Alternatively, you can also use the following code as used by the WithRazorPagesRoot extension method to change the razor pages directory name.
The Application Base (Root) path is available in the ContentRootPath property of the interfaces IHostingEnvironment (. Net Core 2.0) and IWebHostEnvironment (. Net Core 3.0) in ASP.Net Core.
For the Grid, a website's root directory is the …/html folder. This is located in the file path /domains/example.com/html. The root directory can be viewed/accessed through File Manager, FTP, or SSH.
In your "Startup" class in the "Configure" method use next:
app.UsePathBase("/yourBasePath");
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