Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change root path ~/ in Razor in asp.net core

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.

like image 1000
STO Avatar asked Jul 03 '18 13:07

STO


People also ask

How do you change the route on a razor page?

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; }

Which can change the root folder of the razor pages?

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.

Where is the root folder path in asp net core?

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.

How do I find my web root path?

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.


1 Answers

In your "Startup" class in the "Configure" method use next:

app.UsePathBase("/yourBasePath");
like image 185
Yevheniy Tymchishin Avatar answered Oct 13 '22 18:10

Yevheniy Tymchishin