public class Settings
{
public string SiteName;
public string ConnectionString;
}
public class PageContext
{
private readonly Settings _settings;
public PageContext(Settings settings)
{
_settings = settings;
}
public string PageTitle;
public string FullTitle
{
get
{
var title = (PageTitle ?? "").Trim();
if(!string.IsNullOrWhiteSpace(title) &&
!string.IsNullOrWhiteSpace(_settings.SiteName))
{
title += " | ";
}
title += _settings.SiteName.Trim();
return title;
}
}
}
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var settings = new Settings();
settings.SiteName = Configuration["SiteName"];
services.AddSingleton(settings);
services.AddScoped<PageContext>();
}
public class HomeController : Controller
{
private readonly PageContext _pageContext;
public HomeController(PageContext pageContext)
{
_pageContext = pageContext;
}
public IActionResult Index()
{
_pageContext.PageTitle = "";
return View();
}
public IActionResult About()
{
_pageContext.PageTitle = "About";
return View();
}
public IActionResult Error()
{
_pageContext.PageTitle = "Error";
return View();
}
}
@inject PageContext pageContext
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@pageContext.FullTitle</title>
<environment names="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" rel="external nofollow" />
<link rel="stylesheet" href="~/css/site.css" rel="external nofollow" />
</environment>
<environment names="Staging,Production">
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css" rel="external nofollow"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css" rel="external nofollow"
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
<link rel="stylesheet" href="~/css/site.min.css" rel="external nofollow" asp-append-version="true" />
</environment>
</head>
...
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有