在视图中确定ASP.NET Core环境名称

栏目: ASP.NET · 发布时间: 7年前

内容简介:您可以通过执行注入您的视图中的服务IHostingEnvironment@inject Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnv并做一个@ hostingEnv.EnvironmentName

新的ASP.NET核心框架使我们能够为不同的环境执行不同的html:

<environment names="Development">
    <link rel="stylesheet" href="~/lib/material-design-lite/material.css" />
    <link rel="stylesheet" href="~/css/site.css" />
</environment>
<environment names="Staging,Production">
    <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.0.0/css/bootstrap.min.css"
          asp-fallback-href="~/lib/material-design-lite/material.min.css"
          asp-fallback-test-class="hidden" asp-fallback-test-property="visibility" asp-fallback-test-value="hidden"/>
    <link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
</environment>

但是,如何在ASP.NET Core MVC Web应用程序的_Layout.cshtml中确定和可视化当前环境的名称?

例如,我想将环境名称(生产,分期,开发))可视化为HTML注释用于调试目的:

<!-- Environment name: @......... -->

您可以通过执行注入您的视图中的服务IHostingEnvironment

@inject Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnv

并做一个@ hostingEnv.EnvironmentName

代码日志版权声明:

翻译自:http://stackoverflow.com/questions/33719609/determine-asp-net-core-environment-name-in-the-views


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

TED Talks Storytelling: 23 Storytelling Techniques from the Best

TED Talks Storytelling: 23 Storytelling Techniques from the Best

Akash Karia / CreateSpace Independent Publishing Platform / 2015-1-11 / USD 6.99

"Every speaker can put these ideas into practice immediately -- and they should!" ~ Dr. Richard C. Harris, Certified World Class Speaking Coach "An insightful read" ~Dennis Waller, Top 500 Revie......一起来看看 《TED Talks Storytelling: 23 Storytelling Techniques from the Best》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具