mlg*_*g74 0 c# nopcommerce razor
谁能帮助我在 2.8 版本中获得视图的客户角色?我尝试过工作上下文,但错误提示“当前上下文中不存在工作上下文”。我有下面的代码,但它不起作用..
@model BoardsIndexModel
@using Nop.Core.Infrastructure;
@using Nop.Services.Helpers;
@using Nop.Web.Models.Boards;
@using Nop.Core.Domain.Customers;
@using Nop.Services.Customers;
@if (Roles.IsUserInRole("Administrators"))
{
Do that;
}
else
{
Do this;
}
Run Code Online (Sandbox Code Playgroud)
在 nopcommerce 论坛上一位好人的帮助下,我就是这样做的:
@using Nop.Core.Domain.Customers;
@using Nop.Services.Customers;
@using Nop.Core;
@{
bool customerHasRoleX = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.IsInCustomerRole("Administrators");
bool customerHasRoleY = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.IsInCustomerRole("ForumModerators");
}
@if ((customerHasRoleX == true) | (customerHasRoleY == true)) {
}
else
{
Response.Redirect("~/login?ReturnUrl=%2fboards");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2574 次 |
| 最近记录: |