Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "klainer"

Hi thanks! I tried to create custom Athorizate Attribute which is deriveder from AbpMvcAuthorizeAttribute and I have problem with

HandleUnauthorizedRequest

. This method is never called in this CustomAttribute. The same problem is in

AbpAuthorizeAttribute

also not called.

My implementation:

public class CustomMvcAuthorizeAttribute : AbpMvcAuthorizeAttribute
    {
        public ILogger Logger { get; set; }
        public string[] Permissions { get; set; }
        public bool RequireAllPermissions { get; set; }

        public VSDMvcAuthorizeAttribute(params string[] permissions) :base(permissions)
        {
            Logger = NullLogger.Instance;
        }

        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {

            var httpContext = filterContext.HttpContext;

**var message = string.Format("'{0}' unauthorize access.",  httpContext.Request.CurrentExecutionFilePath );
            Logger.Security(message); // my custom security log**
            if (!httpContext.Request.IsAjaxRequest())
            {
                base.HandleUnauthorizedRequest(filterContext);
                return;
            }

            httpContext.Response.StatusCode = httpContext.User.Identity.IsAuthenticated == false
                                      ? (int)System.Net.HttpStatusCode.Unauthorized
                                      : (int)System.Net.HttpStatusCode.Forbidden;

            httpContext.Response.SuppressFormsAuthenticationRedirect = true;
            httpContext.Response.End();

        }

Thanks for help

Hi, I want to extend base AbpMvcAuthorizeFilter (OnAuthorization method) due to custom loging level implementation. I noticed that filter is registered there: AbpWebMvcModule.cs

It is possible to replace this base filter with my own ? How can I do that in WEB module ? Thanks for your time and help!

Solved by virtual keyword in action :) :D

Hello, I´m using kendo grid, with ABP. I have services, which return IQueriable<T> to Web project. I need to use Kendo ToDataSourceResult extension method to filter data based on request params.

DataSourceResult result = gridViews.ToDataSourceResult(request);

But ABP always dispose DB context, so i got exception.

My example:

GridViewDto:

public class GridView : Entity, IMustHaveOrganizationUnit
    {
        public virtual long OrganizationUnitId { get; set; }

        public virtual string ViewName { get; set; }

        [Required]
        public virtual string Key { get; set; }  // název grigu

        [Required]
        public virtual string GridSettings { get; set; }

        [ForeignKey("User_Id")]
        public virtual User User { get; set; } 
        public long? User_Id { get; set; }
    }

    public class GridViewDto
    {
        public virtual string ViewName { get; set; }
        public virtual string Key { get; set; }  // název grigu
        public virtual string GridSettings { get; set; }
        public virtual string UserName { get; set; }
        public long? UserId { get; set; }
    }

SERVICE:

[UnitOfWork]
        public IQueryable<GridViewDto> GetUserGridViews(User user, string key)
        {
            if (user == null)            
                throw new ArgumentNullException("user");

            Mapper.Initialize(cfg =>
                cfg.CreateMap<GridView, GridViewDto>()
                    .ForMember(dto => dto.UserName, conf => conf.MapFrom(ol => ol.User.Name))
                );


            return _gridViewRepository.GetAll().Where(grid => grid.User_Id == user.Id && grid.Key == key).ProjectTo<GridViewDto>();
        }

CONTROLLER:

[DontWrapResult]
        [UnitOfWork]
        public async Task<ActionResult> GridViewDataRead([DataSourceRequest]DataSourceRequest request, string gridId)
        {
            var user = await _userManager.GetUserByIdAsync(AbpSession.UserId.Value);
            var gridViews = _gridViewService.GetUserGridViews(user, gridId);
            DataSourceResult result = gridViews.ToDataSourceResult(request);
            return Json(result, JsonRequestBehavior.AllowGet);
        }
System.InvalidOperationException: The operation cannot be completed because the DbContext has been disposed. 
at System.Data.Entity.Internal.InternalContext.CheckContextNotDisposed() 
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() 
at System.Data.Entity.Internal.InternalContext.Initialize()

Thanks for help

Hi what if I want to make query based on extended attribute ?

When I do this:

private readonly IRepository<MYOrganizationUnit, long> _organizationUnitRepository;

I need this:

_organizationUnitRepository.FirstOrDefault( x =>  x.custmAttribute = "xxx");

I got error, dependency is not satisfied

Thanks

Thanks. Works!

I have another question. In CORE project i create MYOrganizationUnitManager class. I need to insert orgnization unit there:

public class MYOrganizationUnitManager : IDomainService
    {
        private readonly UserManager _userManager;
        private readonly IRepository<OrganizationUnit, long> _organizationUnitRepository;
        private readonly OrganizationUnitManager _organizationUnitManager;
        public MYOrganizationUnitManager(
            UserManager userManager,
            IRepository<OrganizationUnit, long> organizationUnitRepository,
            OrganizationUnitManager organizationUnitManager
            )
        {
            this._userManager = userManager;
            _organizationUnitRepository = organizationUnitRepository;
            _organizationUnitManager = organizationUnitManager;
        }


        public virtual async Task CreateOuStructure()
        {
            // Remove all OU first

            // Get ROOT OU
            var rootUnit = _organizationUnitRepository.GetAll().FirstOrDefault(x => x.DisplayName == "ROOT");
            if (rootUnit == null)
            {
                // Create fresh root unit
                rootUnit = await CreateOu("ROOT", "EN000000");

            }

              var regionUnit = await CreateOu("Child UNIT", "EN570000", rootUnit.Id);
       }



        protected virtual async Task<MYOrganizationUnit> CreateOu(string displayName, string hermesUnitCode, long? parentId = null)
        {
            var ou = new MYOrganizationUnit() { DisplayName = displayName, CustomUnitCode = customUnitCode ,ParentId = parentId };
            await _organizationUnitManager.CreateAsync(ou);
            await _organizationUnitManager.UnitOfWorkManager.Current.SaveChangesAsync();

            return ou;
        }
}

I´m using this (MYOrganizationUnitManager ) in MYApplicationService, and I got this error:

Abp.AbpException: There is no such an entity with given primary key. Entity type: Abp.Organizations.OrganizationUnit, primary key: 13 
v Abp.Domain.Repositories.AbpRepositoryBase`2.&lt;GetAsync&gt;d__16.MoveNext() v D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Repositories\AbpRepositoryBase.cs:řádek 81 
--- Konec trasování zásobníku z předchozího místa, ze kterého byla vyvolána výjimka --- 
v System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
v System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
v System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 
v Abp.Threading.InternalAsyncHelper.<AwaitTaskWithPostActionAndFinallyAndGetResult>d__5`1.MoveNext() v D:\Halil\GitHub\aspnetboilerplate\src\Abp\Threading\InternalAsyncHelper.cs:řádek 120 
--- Konec trasování zásobníku z předchozího místa, ze kterého byla vyvolána výjimka --- 
v System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
v System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
v System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 
v Abp.Organizations.OrganizationUnitManager.<GetCodeAsync>d__10.MoveNext() v D:\Halil\GitHub\module-zero\src\Abp.Zero\Organizations\OrganizationUnitManager.cs:řádek 67 
--- Konec trasování zásobníku z předchozího místa, ze kterého byla vyvolána výjimka --- 
v System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
v System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

This code do not insert new entity to DB, but ID is generated, when iserting new entity i get above error

await _organizationUnitManager.UnitOfWorkManager.Current.SaveChangesAsync();

¨

Thanks for help

Hello, I need to extend OU unit entity with some property, is this even possible ? If so, What is proper way to do that ? I need to store aditional data about entity (another code), only for manage users..

Thanks for tips!

Please can you post code which solved your issue? Thanks !

Hello

I need to use AspNetWindowsTokenRoleProvider with ABP together. In web.config a created these configuration:

<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider">
  <providers>
    <clear />
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
  </providers>
</roleManager>

When I run application I have this problem:

Windows Identity Method is only supported if the user name parameter matches the user name in the current Windows Identity.

This error occurs only when I use ClaimsIdentity to login User. When I login user with WindowIdentity I got another problem with application. My ClaimsIdentity have the same UserName but no work :/

So it is possible to create ClaimsIdentity which work with this role manager ? I need to get USER ActiveDirectory UserGroups / Roles and use it like this:

var User = System.Web.HttpContext.Current.User;
if (User.IsInRole("DOMAIN\\group")){  ...    }

Have anybody solution for windows auto sign on to ABP and use this manager ?

Thanks for HELP !

i have this resource localizable attribute:

public class LocalizedDisplayNameAttribute : DisplayNameAttribute
{
    public LocalizedDisplayNameAttribute(string resourceId)
        : base(GetMessageFromResource(resourceId))
    {

    }

    private static string GetMessageFromResource(string resourceId)
    {
        var ioc = Abp.Dependency.IocManager.Instance;
        var localizationManager = ioc.IocContainer.Resolve<ILocalizationManager>();


        return localizationManager.GetString(MMMConsts.LocalizationSourceName, resourceId, Thread.CurrentThread.CurrentUICulture);}

When I switch language in WEB app, and debug this, In Thread.CurrentThread.CurrentUICulture i still the same value.

But when do this in Razor view culture has changed correctly.

How can I setUp currencu culture in my attribute class , I need it for loading multilanguages texts from resources.

Model attributes are initialized before app start ? Thanks for help !

Solved by this code:

public LocalizedDisplayNameAttribute(string resourceKey)
            : base(resourceKey)
        {
            ResourceKey = resourceKey;
        }

        public string ResourceKey { get; set; }

        public override string DisplayName
        {
            get
            {
                string value = null;
                var ioc = Abp.Dependency.IocManager.Instance;
                var localizationManager = ioc.IocContainer.Resolve<ILocalizationManager>();
                value = localizationManager.GetString(MMMConsts.LocalizationSourceName, ResourceKey, Thread.CurrentThread.CurrentUICulture);

                return value;
            }
        }

c# asp.net-mvc

Showing 1 to 10 of 31 entries