本文整理汇总了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();
});
}
示例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();
});
}
示例3: CombinatorResource
public CombinatorResource(ResourceType type, IHttpContextAccessor httpContextAccessor)
{
_type = type;
_httpContext = httpContextAccessor.Current();
RequiredContext = new ResourceRequiredContext();
IsOriginal = false;
}
示例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
}
示例5: ScriptManager
public ScriptManager(ICacheManager cacheManager, IHttpContextAccessor contextAccessor)
{
_cacheManager = cacheManager;
_context = contextAccessor.Current();
}