我的 ASP.NET Core MVC 应用程序有问题。
谁能告诉我为什么环境(名称)的标签助手在我的(管理)布局页面位于区域内时不起作用?
当使用以下代码引用我的脚本时,它在放入标准 _Layout.cshtml 页面而不是包含在某个区域(用于管理区域)中的 _Layout.cshtml 时起作用。 理想情况下,我正在尝试将我的代码模块化为区域 - 仪表板包含管理区域的这个 _Layout.cshtml 页面。
我发现我所有的 css/js 引用都被包括在内(未缩小和缩小以及 CDN)。所以我将下面的代码放入公共(public)布局和管理布局中。
<environment names="Development">
Development
</environment>
<environment names="Staging,Production">
Staging production
</environment>
~/Views/Shared/_Layout.cshtml(公共(public))
显示“发展”(良好)
~/Areas/Dashboard/Views/Shared/_Layout.cshtml(管理)
显示“Development Staging Production”(坏)
我的环境变量是 ASPNETCORE_ENVIRONMENT(值为 Development)
我的创业
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
Configuration = builder.Build();
}
配置方法 ...
app.UseMvc(routes =>
{
routes.MapRoute(name: "areaRoute",
template: "{area:exists}/{controller=Home}/{action=Index}");
routes.MapRoute(name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
任何帮助都会很棒 - 谢谢。 丹.
最佳答案
听起来好像 tagHelper 没有在区域中注册并且正在被浏览器处理。
environment
之类的 TagHelpers 必须在您的 _ViewImports.cshtml
文件中引用,默认情况下它只会在 /Views
中,但也应该存在于你的每一个领域。
关于c# - 区域布局忽略的环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39109516/