惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
V
Visual Studio Blog
博客园 - 司徒正美
TaoSecurity Blog
TaoSecurity Blog
博客园 - 聂微东
IT之家
IT之家
博客园_首页
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - Franky
雷峰网
雷峰网
罗磊的独立博客
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
The Cloudflare Blog
T
Tailwind CSS Blog
B
Blog RSS Feed
H
Help Net Security
T
The Blog of Author Tim Ferriss
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
C
CERT Recently Published Vulnerability Notes
博客园 - 三生石上(FineUI控件)
P
Palo Alto Networks Blog
I
Intezer
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
S
Securelist
J
Java Code Geeks
V
V2EX
Y
Y Combinator Blog
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
Spread Privacy
Spread Privacy
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog
Forbes - Security
Forbes - Security
Google Online Security Blog
Google Online Security Blog
Help Net Security
Help Net Security
S
SegmentFault 最新的问题
N
Netflix TechBlog - Medium
Webroot Blog
Webroot Blog
Microsoft Security Blog
Microsoft Security Blog
SecWiki News
SecWiki News
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
N
News and Events Feed by Topic

博客园 - MHL

C#:类的成员--事件 SSRS 2016 Forms Authentication 存储配置关系&知识图谱 Neo4j 使用cypher语言进行查询 项目实战--知识图谱初探 - MHL - 博客园 .NET Core多语言 ASP.NET Core WebApi 返回统一格式参数 C#启动外部程序以及等待外部程序关闭的几种方法 开源.net 混淆器ConfuserEx介绍 CRUD Operations In ASP.NET MVC 5 Using ADO.NET 【译】RAID的概念和RAID对于SQL性能的影响 【转】Sql server锁,独占锁,共享锁,更新锁,乐观锁,悲观锁 One Day WinForm简单进度条 金庸群侠传 3小时爆机 ExtJs Set PropertyGrid Column Name ExtJs GridPanel 生成列 电脑上玩 Google纵横 Microsoft Visual Studio 2010 宣传短片
asp.net mvc 利用过滤器进行网站Meta设置
MHL · 2016-02-09 · via 博客园 - MHL

过去几年都是用asp.net webform进行开发东西,最近听说过时了,同时webform会产生ViewState(虽然我已经不用ruanat=server的控件好久了 :)),对企业应用无所谓,但对于互联网应用就不太友好了,这几天学习了一下asp.net mvc,自己做了个网站玩玩(asp.net mvc + bootstrap + html5),随便也学习一下。

网站的组织:

三个网站分别为 index主站、Info信息咨询站、live视频站,利用Areas进行分开

namespace DaiWan.lol.Areas.info.Filter
{
    public class MetaInfo : ActionFilterAttribute
    {
       
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.Controller.ViewBag.meta = Meta();
        }


        private string Meta(string copyright,string keywords, string description, string author)
        {
            StringBuilder s = new StringBuilder();
            string MetaTemplate =@"<meta name = ""Copyright"" content=""#copyright#"" />
<meta name=""keywords"" content=""#keywords#"" />
<meta name=""description"" content=""#description#"" />
<meta name=""author"" content=""#author#"" />";
            return MetaTemplate.Replace("#copyright#", copyright)
                .Replace("#keywords#", keywords)
                 .Replace("#description#", description)
                 .Replace("#author#", author);
        }


        private string Meta()
        {
            string copyright = "带玩,DaiWan";
            string keywords = "英雄联盟,lol,DaiWan,Game,游戏,lol攻略,lol视频,英雄资料,英雄,攻略";
            string description = "DaiWan LOL英雄联盟,为英雄联盟玩家提供最全的英雄联盟出装攻略、英雄联盟视频、客户端下载、战斗力查询、英雄皮肤、最全的英雄资料和物品等信息,掌握第一手资料,不遗漏任何一条英雄联盟的信息,更多精彩";
            string author = "带玩游戏平台";

            return Meta(copyright, keywords, description, author);
        }
    }
}

使用

namespace DaiWan.lol.Areas.info.Controllers
{
    public class HomeController : BaseController
    {
        // GET: info/Home

         [MetaInfo]
        public ActionResult Index()
        {
            ArticleLib lib = new ArticleLib();
            IList<Article> list = lib.List();

            Mapper.CreateMap<Article, ArticleViewMode>();
            IList<ArticleViewMode> ilist = Mapper.Map<IList<ArticleViewMode>>(list);

            return View(ilist);
        }


        // GET: info/Home
        public ActionResult Detail(string guid)
        {
            ArticleLib lib = new ArticleLib();
            Article article = lib.Get(guid);

            Mapper.CreateMap<Article, ArticleViewMode>();
            ArticleViewMode articleviewmode =  Mapper.Map<ArticleViewMode>(article);

            return View(articleviewmode);
        }
    }
}

效果: