如何在asp.net核心中的Razor中更改根路径〜/ [英] How to change root path ~/ in Razor in asp.net core
问题描述
我找不到答案的最简单的问题.
我有一个带有Razor的asp.net核心2.1 MVC应用程序.
应用程序广泛使用~/path
语法.
如果应用程序从域根目录运行(例如,从 http://localhost:5000/)运行,则一切正常>
但是,当我在非根目录下运行应用程序时(例如, http://localhost:5000/app ),剃刀仍然使用根(/
)作为基本路径.
问题:如何配置?如何为Razor的~/
指定基本路径?必须有一个环境变量:)
PS:应用程序在反向代理后面的docker中运行.
在启动"类的配置"方法中,使用下一个:
app.UsePathBase("/yourBasePath");
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.
In your "Startup" class in the "Configure" method use next:
app.UsePathBase("/yourBasePath");
这篇关于如何在asp.net核心中的Razor中更改根路径〜/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!