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

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
小众软件
小众软件
量子位
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Jina AI
Jina AI
T
Threat Research - Cisco Blogs
博客园_首页
The Hacker News
The Hacker News
C
Cyber Attacks, Cyber Crime and Cyber Security
有赞技术团队
有赞技术团队
宝玉的分享
宝玉的分享
Security Latest
Security Latest
博客园 - 叶小钗
The Last Watchdog
The Last Watchdog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
IT之家
IT之家
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
Lohrmann on Cybersecurity
V
V2EX
P
Proofpoint News Feed
I
Intezer
云风的 BLOG
云风的 BLOG
Spread Privacy
Spread Privacy
罗磊的独立博客
H
Help Net Security
T
Tor Project blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
Schneier on Security
Blog — PlanetScale
Blog — PlanetScale
L
LINUX DO - 热门话题
D
DataBreaches.Net
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
Simon Willison's Weblog
Simon Willison's Weblog
Latest news
Latest news
P
Proofpoint News Feed
NISL@THU
NISL@THU
Y
Y Combinator Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Security @ Cisco Blogs

博客园 - 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);
        }
    }
}

效果: