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

推荐订阅源

博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
G
Google Developers Blog
B
Blog
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 叶小钗
The Cloudflare Blog
The Hacker News
The Hacker News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
雷峰网
雷峰网
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
量子位
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
H
Help Net Security
Help Net Security
Help Net Security
P
Palo Alto Networks Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Troy Hunt's Blog
W
WeLiveSecurity
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
Know Your Adversary
Know Your Adversary
Apple Machine Learning Research
Apple Machine Learning Research
Scott Helme
Scott Helme
N
News | PayPal Newsroom
AWS News Blog
AWS News Blog
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
腾讯CDC
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
GbyAI
GbyAI
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker

博客园 - 灰灰狼

架构与设计概要 IoC概要 需求分析概要 接上文,支持并发数量的完美版本 消息队列并发处理基类-简化版 2013年5.28~7.27 Microsoft FTE 微软面试总结 String Format for DateTime 多语言建议 问题观 New life I would like About that task about wcf 基于证书的WCF安全开发详解 asp.net缓存(20100804完善版) - 灰灰狼 - 博客园 呼唤程序员精神——关于我今天发起的讨论的总结 asp.net mvc下实现窗口不关闭,就让Session不过期 正确的产品开发策略
multi-language
灰灰狼 · 2010-11-02 · via 博客园 - 灰灰狼

LocalizationHelper类可改进之处:

1.不应对Controller做使用局部资源的扩展,因为Controller里只应该知道全局资源。

public static string Resource(this Controller controller, string expression, params object[] args)

        {

            return GetLangString(controller.HttpContext, expression, "~/Views" + controller.HttpContext.Request.Path + ".aspx", args);

        }

原因是:

首先,从松耦合设计的角度考虑,View相对于Controller应该是透明的,找ViewViewEngine的职责,Controller只需要知道View的名字,而不需要也不应该知道其位置。在asp.net MVC里通过View的名字找具体的View的机制是松耦合的, 默认实现是WebFormViewEngine类,这个类继承自VirtualPathProviderViewEngine,而VirtualPathProviderViewEngine实现了IViewEngine,理论上只要实现了IViewEngine接口的类均可以有自己的方式来作为查找View的机制,而不一定按"~/Views" + controller.HttpContext.Request.Path + ".aspx"来定位。

其次,客观上只有找的是Page,且"~/Views" + controller.HttpContext.Request.Path + ".aspx"及对应的资源文件存在的时候才会正常运行,一旦ViewUserControl或者位置在Share目录就会找不到,而出异常。

建议的解决方案:

1)在Controller只可以访问全局资源

2)如果非要用局部资源,则只应在Model里存入Key,访问具体局部资源的过程要推迟到View阶段。

方案二:

(1)      修改Html.Resource方法,完善其查找View的途径,让它的机制与WebFormViewEngine的机制相同。

方案二的修改难度低,只需要修改Resource方法,不必改Controller里的代码。但它使Html类与具体类WebFormViewEngine产生了强耦合,违反低耦合设计原则。

2.性能改进: 每取一次资源,就会new一个CultureInfo对象,具体请看GetResourceString方法,Language.GetCurrentLanguageFormat()也存在同样的性能问题。

结合以前的研究,我提出以下改进建议:

(1)      定义系统支持的语言列表,列表中第一项为默认语言,系统运行后,建立与语言列表对应的一组CultureInfo对象,在后续的请求中需要哪个就用哪个,不需要再New对象。

(2)      页面上添加选择语言的选项,可让用户来选择想看的语言。选择语言对应的逻辑是用JS修改Cookie并刷新页面。