标签:param 使用 ref pipe return spn middle https prepare
在Asp.net 4.x时代,我们通常的做法是通过HttpContext.Current获取当前请求的上下文进而获取到当前的User属性,所以问题的切入点在于我们如何获取当前的HttpContext上下文。
在我们的Aspnet Core应用中,系统是通过注入HttpContext的访问器对象IHttpContextAccessor来获取当前的HttpContext。
/// <summary> /// Register HttpContextAccessor /// </summary> /// <param name="services">Collection of service descriptors</param> public static void AddHttpContextAccessor(this IServiceCollection services) { services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); }
public virtual IActionResult GeneralCommon() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings)) return AccessDeniedView(); //prepare model var model = _settingModelFactory.PrepareGeneralCommonSettingsModel(); //notify admin that CSS bundling is not allowed in virtual directories if (model.MinificationSettings.EnableCssBundling && HttpContext.Request.PathBase.HasValue) _notificationService.WarningNotification(_localizationService.GetResource("Admin.Configuration.Settings.GeneralCommon.EnableCssBundling.Warning")); return View(model); }
public Task Invoke(Microsoft.AspNetCore.Http.HttpContext context, IWebHelper webHelper, IWorkContext workContext) { //set culture SetWorkingCulture(webHelper, workContext); //call the next middleware in the request pipeline return _next(context); }
namespace OrchardCore.Modules { public class DefaultOrchardHelper : IOrchardHelper { public DefaultOrchardHelper(IHttpContextAccessor httpContextAccessor) { HttpContext = httpContextAccessor.HttpContext; } public HttpContext HttpContext { get; set; } } }
net4.x MVC架构迁移到asp.net core要点记录
标签:param 使用 ref pipe return spn middle https prepare
原文地址:https://www.cnblogs.com/gougou1981/p/12307942.html