这是HTML辅助线程安全的? [英] Is this html helper thread safe?
问题描述
我想知道如果因为这个链接上公认的答案作为参考的code是线程安全的。我的意思是不是多线程。我只是不想输出交叉用户页面的请求。结果
<一href=\"http://stackoverflow.com/questions/5110028/add-css-or-js-files-to-layout-head-from-views-or-partial-views/5148224#5148224\">Add从视图或局部视图CSS或JS文件布局头部
I am wondering if the code as referenced as the accepted answer on this link is thread safe. I mean not for multi threading. I just dont want output crossing user page requests.
Add css or js files to Layout Head from views or partial views
我本来有许多请求一个页面可能越过样式和脚本的情况。
Would I have a situation where many requests to a page could have crossed over styles and scripts.
如果你有在MVC的知识被称为add方法的观点被渲染,并将结果呈现给布局(母版页),它可以帮助。
It may help if you have knowledge of MVC in that the add methods are called as views are rendered and the result is rendered to the layout (master page).
当前解决方案(请让我知道它是否应该改进)
public static MyCompanyHtmlHelpers GetInstance(HtmlHelper htmlHelper)
{
MyCompanyHtmlHelpers _instance;
if (htmlHelper.ViewData["SectionHelper"] == null)
{
_instance = new MyCompanyHtmlHelpers();
htmlHelper.ViewData["SectionHelper"] = _instance;
}
else
_instance = htmlHelper.ViewData["SectionHelper"] as MyCompanyHtmlHelpers;
_instance.SetHtmlHelper(htmlHelper);
return _instance;
}
感谢
推荐答案
嗯....看起来并不像它给了我; P
Hmm.... doesn't look like it to me ;p
的HtmlHelper
有一些实例属性,特别是 ViewContext
和的ViewData code>(通过
ViewDataContainer
)等,把任何地方静态
是一个可怕可怕的想法。
HtmlHelper
has some instance properties, in particular ViewContext
and ViewData
(via ViewDataContainer
) etc. Putting that anywhere static
is a terrible terrible idea.
使用基本code这是怎么回事你的可能的摆脱它,但是:IMO这仍然是一个非常糟糕的主意。那么斑点。
With the basic code that is going on you'll probably get away with it, but: IMO this is still a very bad idea. Well spotted.
这篇关于这是HTML辅助线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!