当前位置: 首页>>代码示例>>C#>>正文


C# IHttpContextAccessor.Current方法代码示例

本文整理汇总了C#中IHttpContextAccessor.Current方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpContextAccessor.Current方法的具体用法?C# IHttpContextAccessor.Current怎么用?C# IHttpContextAccessor.Current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHttpContextAccessor的用法示例。


在下文中一共展示了IHttpContextAccessor.Current方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UrlAlternatesFactory

        public UrlAlternatesFactory(IHttpContextAccessor httpContextAccessor) {
            _httpContextAccessor = httpContextAccessor;

            _urlAlternates = new Lazy<List<string>>(() => {
                var httpContext = _httpContextAccessor.Current();

                if (httpContext == null) {
                    return null;
                }

                var request = _httpContextAccessor.Current().Request;

                // extract each segment of the url
                var urlSegments = VirtualPathUtility.ToAppRelative(request.Path.ToLower())
                    .Split('/')
                    .Skip(1) // ignore the heading ~ segment 
                    .Select(url => url.Replace("-", "__").Replace(".", "_")) // format the alternate
                    .ToArray();

                if (String.IsNullOrWhiteSpace(urlSegments[0])) {
                    urlSegments[0] = "homepage";
                }

                return Enumerable.Range(1, urlSegments.Count()).Select(range => String.Join("__", urlSegments.Take(range))).ToList();
            });
        }
开发者ID:cmacri,项目名称:Orchard,代码行数:26,代码来源:UrlAlternatesFactory.cs

示例2: ActionAlternatesFactory

		public ActionAlternatesFactory(IHttpContextAccessor httpContextAccessor)
		{
			_httpContextAccessor = httpContextAccessor;

			_actionAlternates = new Lazy<List<string>>(() =>
			{
				var httpContext = _httpContextAccessor.Current();

				if (httpContext == null)
				{
					return null;
				}

				var request = _httpContextAccessor.Current().Request;

				var actionSegments = new[] 
				{
					request.RequestContext.RouteData.GetRequiredString("area").Replace("-", "__").Replace(".", "_"), 
					request.RequestContext.RouteData.GetRequiredString("controller").Replace("-", "__").Replace(".", "_"), 
					request.RequestContext.RouteData.GetRequiredString("action").Replace("-", "__").Replace(".", "_")
				};

				return Enumerable.Range(1, actionSegments.Count()).Select(range => String.Join("__", actionSegments.Take(range))).ToList();
			});
		}
开发者ID:dminik,项目名称:voda_code,代码行数:25,代码来源:ActionAlternatesFactory.cs

示例3: CombinatorResource

        public CombinatorResource(ResourceType type, IHttpContextAccessor httpContextAccessor)
        {
            _type = type;
            _httpContext = httpContextAccessor.Current();

            RequiredContext = new ResourceRequiredContext();
            IsOriginal = false;
        }
开发者ID:hqmirror,项目名称:Combinator,代码行数:8,代码来源:CombinatorResource.cs

示例4: CounterService

        public CounterService(
            IContentManager manager,
            IHttpContextAccessor context,
            Lazy<IRepository<CounterRecord>> repo) {
            _locks = new ConcurrentDictionary<string, object>();
            _manager = manager;
            _context = context;
            _repo = repo;

            if (_context == null || _context.Current() == null || _context.Current().Session == null) {
                return;
            }
            // ReSharper disable PossibleNullReferenceException
            var dict = _context.Current().Session[SessionKey] as ConcurrentDictionary<string, SerializableCounter>;
            // ReSharper restore PossibleNullReferenceException
            if (dict == null) {
                // ReSharper disable PossibleNullReferenceException
                _context.Current().Session[SessionKey] = new ConcurrentDictionary<string, SerializableCounter>();
            }
            // ReSharper restore PossibleNullReferenceException
        }
开发者ID:richinoz,项目名称:Orchard1.6,代码行数:21,代码来源:CounterService.cs

示例5: ScriptManager

 public ScriptManager(ICacheManager cacheManager, IHttpContextAccessor contextAccessor)
 {
     _cacheManager = cacheManager;
     _context = contextAccessor.Current();
 }
开发者ID:philpeace,项目名称:CodePeace.StrawberryJam,代码行数:5,代码来源:ScriptManager.cs


注:本文中的IHttpContextAccessor.Current方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。