asp.net-mvc - 如何在 nopcommerce 4.2 的通用控制器中使用 IsMobileDevice()
问题描述
我想在通用控制器中使用 IsMobileDevice()。但是当我使用这种方法时,它向我显示错误,即
1. 激活特定注册时发生错误。有关详细信息,请参阅内部异常。注册:Activator = CommonController (ReflectionActivator), Services = [Nop.Web.Controllers.CommonController], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> 没有找到带有 'Autofac 的构造函数'Nop.Web.Controllers.CommonController' 类型上的 .Core.Activators.Reflection.DefaultConstructorFinder' 可以使用可用的服务和参数调用:
2. 无法解析构造函数'Void.ctor(Nop.Core.Domain.Security.CaptchaSettings, Nop.Core.Domain.Common.CommonSettings, Nop.Web.Factories.ICommonModelFactory, Nop.Services.Directory.ICurrencyService、Nop.Services.Logging.ICustomerActivityService、Nop.Services.Common.IGenericAttributeService、Nop.Services.Localization.ILanguageService、Nop.Services.Localization.ILocalizationService、Nop.Services.Logging.ILogger、Nop。 Core.IStoreContext、Nop.Web.Framework.Themes.IThemeContext、Nop.Services.Vendors.IVendorService、Nop.Core.IWorkContext、Nop.Services.Messages.IWorkflowMessageService、Nop.Core.Domain.Localization.LocalizationSettings、Nop.Core。 Domain.Common.SitemapSettings、Nop.Core.Domain.Common.SitemapXmlSettings、Nop.Core.Domain.StoreInformationSettings、Nop.Core。Domain.Vendors.VendorSettings,Nop.Services.Helpers.UserAgentHelper)'。
这是我如何在通用控制器中使用此方法的代码行
var mobileDevice = _userAgentHelper.IsMobileDevice();
这里是领域
private readonly IHttpContextAccessor _httpContextAccessor;
为什么在运行时显示错误?
解决方案
我刚刚在 nopCommerce 4.20 中检查了通用控制器中的 IsMobileDevice 方法及其工作正常,它将返回 true 或 false,我尝试过使用 google chrome
这是我实现的代码
private readonly IUserAgentHelper _userAgentHelper;
public CommonController(IUserAgentHelper userAgentHelper)
{
_userAgentHelper = userAgentHelper;
}
public virtual IActionResult ContactUs()
{
var model = new ContactUsModel();
var mobileDevice = _UserAgentHelper.IsMobileDevice();
if(mobileDevice)
return true;
model = _commonModelFactory.PrepareContactUsModel(model, false);
return View(model);
}
推荐阅读
- kotlin - 如何将 lambda 链接到 Kotlin 中的结果 lambda?
- android - Android Google Maps:使用 ClusterManager 和 ClusterRenderer 时,如何检测或提醒某个项目不再显示?
- docker - 从 bash 脚本运行时,集成测试卡在启动时
- weka - 为什么我的 weka 没有按班级显示详细的准确性
- javascript - 按帐户类型过滤对象的 Javascript 数组
- android - 如何在 GIF 搜索模式下显示软输入键盘 (gboard)
- typescript - 无法在打字稿代码中找到 docusign 模型
- excel - 自动计算excel上的彩色单元格
- javascript - Vue:用于检查未更新元素的 offsetHeight 的计算属性
- php - 这可以在没有 Alpine Js 的情况下转换为 Livewire 组件或简化为 livewire 组件(标签输入)