JohnI''d like to store information for roles in Session variables. RoleAhas a specific set of values, RoleB has a specific set and so one.When I access values for RoleA, it looks like this:Session[Utils.RoleA_MBcount] = "30"Session[Utils.RoleA_BandwidthLimit] = "1000"Session[Utils.RoleA_FeatureBcountLimit] = "5"Session[Utils.RoleA_FeatureCcountLimit] = "10"and similar for the other roles. Those values are initially loadedfrom a database. Each role is actually a purchased plan. Similar tovarious hosting plans that give you more the more you pay. Once theroles are initialized into Session variables, I just access theSession variable to check user limits.Each of the above properties in Utils is a static string reference.They''re just nice ways to give me intellisense and avoid hard codingstrings everywhere. The problem is that I''ll have to hit the Utils.csfile everytime I want to use these lookup values. If there are fourroles and each one has 10 properties that could be a lot of hits(especially with more roles) depending on how grouped the lookups arethrough out the app.Is this a concern or is there a better way?Thanks,John推荐答案" john_c" < jo *** @ bigstring.comwrote in message news:11 ********************** @ a75g2000cwd.googlegr oups .com ..."john_c" <jo***@bigstring.comwrote in messagenews:11**********************@a75g2000cwd.googlegr oups.com... 问题是每次我想要使用时我都必须点击Utils.cs文件这些查找值。The problem is that I''ll have to hit the Utils.cs file everytime I want touse these lookup values. 实际上,你不是...... Utils.cs文件,就像你所有的其他C#代码文件一样, 是在重建应用程序时编译到您的Web应用程序的DLL中,这是在应用程序启动时加载到内存中的 ...In fact, you don''t... The Utils.cs file, like all your other C# code files,is compiled up into your web app''s DLL when you rebuild the app, which isloaded into memory when the app starts... 这是一个问题还是有更好的方法?Is this a concern or is there a better way? 我不会认为这是一个问题... 至于更好的方式,那个' '有点难以说......其他方面肯定有 - 你可以使用其中一个Collection对象(例如ArrayList)或 泛型对象(例如Dictionary)如果您正在使用ASP.NET v2,或者您可以在会话中单独保存每个元素 - 如果有任何性能 差异,我们可能正在寻找在纳秒......I wouldn''t have thought it was a concern...As for a better way, that''s a little difficult to say... There are certainlyother ways - you could use one of the Collection objects (e.g. ArrayList) orGenerics objects (e.g. Dictionary) if you''re using ASP.NET v2, or you couldhold each element separately in Session - if there are any performancedifferences, we''re probably looking at nanoseconds... 2月20日下午3:34,Mark Rae < m ... @ markNOSPAMrae.comwrote:On Feb 20, 3:34 pm, "Mark Rae" <[email protected]: " john_c" < j ... @ bigstring.comwrote in message 新闻:11 ********************** @ a75g2000cwd.googlegr oups.com ..."john_c" <[email protected] in messagenews:11**********************@a75g2000cwd.googlegr oups.com... 问题是我每次都要点击Utils.cs文件 使用这些查找值。 The problem is that I''ll have to hit the Utils.cs file everytime I want to use these lookup values. 实际上,你不是...... Utils.cs文件,就像你所有的其他C#代码文件一样, 是在重建应用程序时编译到您的Web应用程序的DLL中,这是在应用程序启动时加载到内存中的 ...In fact, you don''t... The Utils.cs file, like all your other C# code files,is compiled up into your web app''s DLL when you rebuild the app, which isloaded into memory when the app starts... 你是对的马克。谢谢。我想是静态的 accessor扔给我 off。这些静态属性是否会在内存中保留 用户会话或应用会话的长度?You''re right Mark. Thanks. I guess the "static" accessor threw meoff. Do these static properties stay in memory for the length of theuser session or app session? >> 这是一个问题还是有更好的方法? Is this a concern or is there a better way? 我不会认为这是一个问题... 至于更好的方式,那个' '有点难以说......其他方面肯定有 - 你可以使用其中一个Collection对象(例如ArrayList)或 泛型对象(例如Dictionary)如果您正在使用ASP.NET v2,或者您可以在会话中单独保存每个元素 - 如果有任何性能 差异,我们可能正在寻找在纳秒...I wouldn''t have thought it was a concern...As for a better way, that''s a little difficult to say... There are certainlyother ways - you could use one of the Collection objects (e.g. ArrayList) orGenerics objects (e.g. Dictionary) if you''re using ASP.NET v2, or you couldhold each element separately in Session - if there are any performancedifferences, we''re probably looking at nanoseconds... 我使用的是ASP.NET 2.0。可以使用一个集合,但我认为更好的方法是在Utils类中按静态类对每个角色进行分组, 这也是静态的。这只是一个很好的intellisense布局。所以 你会得到 Session [Utils.Roles.RoleA.MBcount] Session [Utils.Roles.RoleA。 BandwidthLimit] Session [Utils.Roles.RoleA.FeatureBcountLimit] Session [Utils.Roles.RoleA.FeatureCcountLimit]I am using ASP.NET 2.0. A collection could be used but I think abetter way is to group each role by static class in the Utils class,which is also static. This just gives a nice intellisense layout. Soyou would haveSession[Utils.Roles.RoleA.MBcount]Session[Utils.Roles.RoleA.BandwidthLimit]Session[Utils.Roles.RoleA.FeatureBcountLimit]Session[Utils.Roles.RoleA.FeatureCcountLimit]此外,每个计划都有相应的应用程序缓存。 将用户会话值与之进行比较。这意味着只需要在应用程序加载时为每个新用户点击 数据库 (会话)。Also, there will be corresponding Application cache for each plan.The user Session values are compared against it. This means thedatabase only needs to be hit when the app loads and for each new user(session). 这篇关于存储查找变量的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-14 09:25