Привет
Мне нужно пользовательское разрешение динамической роли в Asp Core
и Angular6
с Identity Core 2.2
по Web Api
Когда мне нужно вернуть список ролей для показа в выпадающем меню, он показывает мне эту ошибку:
SyntaxError: JSON.parse: неожиданный конец данных в строке 1 столбца 1 данных JSON
Теперь : Как я могу решить эту проблему для возврата списка ролей?
Это мой код:
RoleManagerController:
private readonly IApplicationRoleManager _roleManag;
public RoleManagerController(IApplicationRoleManager roleManag)
{
_roleManag = roleManag;
}
[HttpGet]
[Route("GetRoles")]
public async Task<List<Role>> GetRoles()
{
var res =await _roleManag.GetAllCustomRolesAsync();
return res;
}
IApplicationRoleManager:
public interface IApplicationRoleManager : IDisposable
{
Task<List<Role>> GetAllCustomRolesAsync();
}
ApplicationRoleManager:
public class ApplicationRoleManager : RoleManager<Role>, IApplicationRoleManager
{
private readonly IHttpContextAccessor _contextAccessor;
private readonly IUnitOfWork _uow;
private readonly IdentityErrorDescriber _errors;
private readonly ILookupNormalizer _keyNormalizer;
private readonly ILogger<ApplicationRoleManager> _logger;
private readonly IEnumerable<IRoleValidator<Role>> _roleValidators;
private readonly IApplicationRoleStore _store;
private readonly DbSet<User> _users;
public ApplicationRoleManager(
IApplicationRoleStore store,
IEnumerable<IRoleValidator<Role>> roleValidators,
ILookupNormalizer keyNormalizer,
IdentityErrorDescriber errors,
ILogger<ApplicationRoleManager> logger,
IHttpContextAccessor contextAccessor,
IUnitOfWork uow) :
base((RoleStore<Role, ApplicationDbContexct, int, UserRole, RoleClaim>)store, roleValidators, keyNormalizer, errors, logger)
{
_store = store;
_store.CheckNullArgument(nameof(_store));
_roleValidators = roleValidators;
_roleValidators.CheckNullArgument(nameof(_roleValidators));
_keyNormalizer = keyNormalizer;
_keyNormalizer.CheckNullArgument(nameof(_keyNormalizer));
_errors = errors;
_errors.CheckNullArgument(nameof(_errors));
_logger = logger;
_logger.CheckNullArgument(nameof(_logger));
_contextAccessor = contextAccessor;
_contextAccessor.CheckNullArgument(nameof(_contextAccessor));
_uow = uow;
_uow.CheckNullArgument(nameof(_uow));
_users = _uow.Set<User>();
}
public async Task<List<Role>> GetAllCustomRolesAsync()
{
return await Roles.ToListAsync();
}
Редактировать
Новая ошибка:
Ошибка ...............................
Запуск:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.Configure<SiteSetting>(options => Configuration.Bind(options));
services.AddDbContext<ApplicationDbContexct>(option =>
option.UseSqlServer(Configuration.GetConnectionString("ApplicationConnectionString")));
services.AddIdentity<User, Role>()
.AddEntityFrameworkStores<ApplicationDbContexct>()
.AddDefaultTokenProviders();
services.AddScoped<IApplicationRoleStore, ApplicationRoleStore>();
services.AddScoped<RoleStore<Role, ApplicationDbContexct, int, UserRole, RoleClaim>, ApplicationRoleStore>();
services.AddScoped<IApplicationRoleManager, ApplicationRoleManager>();
services.AddScoped<RoleManager<Role>, ApplicationRoleManager>();
services.AddScoped<IUnitOfWork,ApplicationDbContexct>();
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
}