BaseSEOPage统一设置网站SEO

代码:

public class BaseSeoPage : System.Web.UI.Page
    {
        protected override void OnPreLoad(EventArgs e)
        {
            base.OnPreLoad(e);
            #region 设置网站SEO
            this.Page.Title = ConfigHelper.title;
            this.Page.MetaKeywords = ConfigHelper.keywords;
            this.Page.MetaDescription = ConfigHelper.description;
            #endregion
        }
    }

各个页面继承就行了

MVC代码:

public class WebBaseController : Controller
    {
        public WebBaseController()
        {
            ViewBag.PageTitle = ConfigUtil.title;
            ViewBag.PageKeywords = ConfigUtil.keywords;
            ViewBag.PageDescription = ConfigUtil.description;
        }
    }

然后各个Controller继承这个,用法很简单:<title>@ViewBag.PageTitle</title>

原文地址:https://www.cnblogs.com/xsj1989/p/6805792.html