123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Web;
- namespace Bowin.Web.Controls.Mvc
- {
- public static class ControlHelper
- {
- static System.Collections.Concurrent.ConcurrentDictionary<HttpContext, IList<string>> scriptRegisterCache;
- static ControlHelper()
- {
- scriptRegisterCache = new System.Collections.Concurrent.ConcurrentDictionary<HttpContext, IList<string>>();
- scriptRegisterCache.TryAdd(HttpContext.Current, new List<string>());
- }
- public static bool IsRegisterScript(this HttpContext httpContext, string scriptKey)
- {
- return GetRegisterKeyList(httpContext).Contains(scriptKey);
- }
- public static void RegisterScript(this HttpContext httpContext, string scriptKey)
- {
- if (IsRegisterScript(httpContext, scriptKey))
- {
- throw new Exception(string.Format("当前HttpContext已经脚本key:{0}", scriptKey));
- }
- GetRegisterKeyList(httpContext).Add(scriptKey);
- }
- public static IList<string> GetRegisterKeyList(this HttpContext httpContext)
- {
- IList<string> scriptKeyList = new List<string>();
- var isRegisterContext = scriptRegisterCache.TryGetValue(httpContext, out scriptKeyList);
- if (!isRegisterContext)
- {
- scriptRegisterCache.TryAdd(HttpContext.Current, new List<string>());
- scriptKeyList = new List<string>();
- }
- return scriptKeyList;
- }
- }
- }
|