Base solution for your next web application

Activities of "klainer"

i have this entity Page:

public class Page : FullAuditedEntity<int, User>, IMultiLanguageEntity<PageTranslation>
{

    public string Name { get; set; }
    public string Content{ get; set; }

    public Page()
    {
        Translations = new List<PageTranslation>();
    }

    public virtual IList<PageTranslation> Translations { get; set; }
}

And entity PageTranslation:

[Table("PageTranslations")]
public class PageTranslation : Entity<int>, IEntityTranslation<Page>
{
    public Page Core { get; set; }
    public int CoreId { get; set; }
    public string Language { get; set; }

    public string Name { get; set; }
    public string Content{ get; set; }
}

I want to update page entity with updated values and tranlsations, so I call this service:

public void UpdatePage(UpdatePageInput input)
    {
        var item = _pageRepository.Get(input.Id);
        item.Content = input.Content;
        item.Description = input.Description;
        item.Title = input.Title;
        item.Name = input.Name;
        item.Translations.Clear(); // there is a problem
        item.Translations.addRange(input.Translations);
    }

When I call item.Translations.Clear() method I got this exception:

The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.

How to solve this in ABP ?

Thanks for help !

Hello I finaly used Mixed Auth project for owin windows SSO. (<a class="postlink" href="https://github.com/MohammadYounes/OWIN-MixedAuth">https://github.com/MohammadYounes/OWIN-MixedAuth</a>)

I had to create MySession class which extended base AbpSession class, because I have problem with UserId property which is not setted.

public class MySession : ClaimsAbpSession
    {

        public MySession(IMultiTenancyConfig multiTenancy) : base(multiTenancy)
        {
        }

        protected object ExecuteScalar(SqlCommand command)
        {
            object obj2;
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString))
            {
                connection.Open();
                command.Connection = connection;
                using (command)
                {
                    obj2 = command.ExecuteScalar();
                }
                connection.Close();
            }
            return obj2;
        }

        public override long? UserId
        {
            get
            {
                var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;
                if (claimsPrincipal == null)
                {
                    return null;
                }

                var claimsIdentity = claimsPrincipal.Identity as WindowsIdentity;
                if (claimsIdentity == null)
                {
                    return base.UserId;
                }

                if (claimsIdentity.Name == "")
                {
                    return null;
                }

                SqlCommand command = new SqlCommand("SELECT Id from AbpUsers where UserName = @UserName AND IsDeleted = 0; SELECT SCOPE_IDENTITY();");
                SqlParameter parmaeter = new SqlParameter { DbType = DbType.String, ParameterName = "@UserName", Value = claimsIdentity.Name };
                command.Parameters.Add(parmaeter);
                var vyseldek = Convert.ToInt32(ExecuteScalar(command));

                return vyseldek;
            }
        }
    }

I got user id from DB by his windows Indentity name.

In web module preIntialize method: IocManager.Register<IAbpSession, MySession>();

Anonymus auth must be enabled in Web project , ofcourse windows auth too.

This is my solution, if you have better way share it.

When I=m creating user by your method i got this error (only on IE, chrome works with out error (this I do not understand)):

V aplikaci / došlo k chybě serveru.

Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values. 
  Popis: Při provádění aktuálního webového požadavku došlo k neošetřené výjimce. Další informace o chybě a o jejím původu v kódu naleznete v trasování zásobníku. 

 Podrobnosti o výjimce: System.Data.Entity.Core.UpdateException: Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values.

Zdrojová chyba: 



Řádek 475:                    Logger.Debug("Vytváření uživatele: " + createUser.UserName);
Řádek 476:
Řádek 477:                    var newUser = _userManager.Create(createUser);
Řádek 478:
Řádek 479:                    Logger.Debug("Konec vytváření uživatele: ");
  

 Zdrojový soubor:  C:\Projects\\TT.Web\Controllers\AccountController.cs    Řádek:  477

I must create manual insert by this code to get it work. Create user with user manager have error above...

SqlCommand command = new SqlCommand(
                "INSERT INTO [AbpUsers] ([TenantId] ,[AuthenticationSource],[Name],[Surname],[UserName],[Password] ,[EmailAddress]"+
                ",[IsEmailConfirmed],[EmailConfirmationCode],[PasswordResetCode] ,[LastLoginTime],[IsActive],[IsDeleted],[DeleterUserId]" +
                ",[DeletionTime] ,[LastModificationTime],[LastModifierUserId],[CreationTime],[CreatorUserId] ,[Company] )" +
                "VALUES ( @TenantId, @AuthenticationSource, @Name, @Surname, @UserName, @Password, @EmailAddress, @IsEmailConfirmed, @EmailConfirmationCode , @PasswordResetCode, " +
                "@LastLoginTime, @IsActive, @IsDeleted, @DeleterUserId, @DeletionTime, @LastModificationTime , @LastModifierUserId, @CreationTime," +
                "@CreatorUserId, @Company ); SELECT SCOPE_IDENTITY();");

            SqlParameter parameter3 = new SqlParameter { DbType = DbType.Int32, ParameterName = "@TenantId", Value = 1 };
            SqlParameter parameter4 = new SqlParameter { DbType = DbType.String, ParameterName = "@AuthenticationSource", Value = DBNull.Value };
            SqlParameter parameter5 = new SqlParameter { DbType = DbType.String, ParameterName = "@Name", Value = createUser2.UserName };
            SqlParameter parameter6 = new SqlParameter { DbType = DbType.String, ParameterName = "@Surname", Value = createUser2.UserName };
            SqlParameter parameter7 = new SqlParameter { DbType = DbType.String, ParameterName = "@UserName", Value = createUser2.UserName };
            SqlParameter parameter8 = new SqlParameter { DbType = DbType.String, ParameterName = "@Password", Value = createUser2.UserName };
            SqlParameter parameter9 = new SqlParameter { DbType = DbType.String, ParameterName = "@EmailAddress", Value = createUser2.UserName };
            SqlParameter parameter10 = new SqlParameter { DbType = DbType.Boolean, ParameterName = "@IsEmailConfirmed", Value = true };
            SqlParameter parameter11 = new SqlParameter { DbType = DbType.String, ParameterName = "@EmailConfirmationCode", Value = DBNull.Value };
            SqlParameter parameter12 = new SqlParameter { DbType = DbType.String, ParameterName = "@PasswordResetCode", Value = DBNull.Value };
            SqlParameter parameter13 = new SqlParameter { DbType = DbType.DateTime, ParameterName = "@LastLoginTime", Value = DBNull.Value };
            SqlParameter parameter14 = new SqlParameter { DbType = DbType.Boolean, ParameterName = "@IsActive", Value = true };
            SqlParameter parameter15 = new SqlParameter { DbType = DbType.Boolean, ParameterName = "@IsDeleted", Value = false };
            SqlParameter parameter16 = new SqlParameter { DbType = DbType.Int32, ParameterName = "@DeleterUserId", Value = DBNull.Value };
            SqlParameter parameter17 = new SqlParameter { DbType = DbType.DateTime, ParameterName = "@DeletionTime", Value = DBNull.Value };
            SqlParameter parameter18 = new SqlParameter { DbType = DbType.DateTime, ParameterName = "@LastModificationTime", Value = DBNull.Value };
            SqlParameter parameter19 = new SqlParameter { DbType = DbType.Int32, ParameterName = "@LastModifierUserId", Value = DBNull.Value };
            SqlParameter parameter20 = new SqlParameter { DbType = DbType.DateTime, ParameterName = "@CreationTime", Value = DateTime.Now };
            SqlParameter parameter21 = new SqlParameter { DbType = DbType.Int32, ParameterName = "@CreatorUserId", Value = 2 };
            SqlParameter parameter22 = new SqlParameter { DbType = DbType.String, ParameterName = "@Company", Value = createUser2.Com };

            command.Parameters.Add(parameter3);
            command.Parameters.Add(parameter4);
            command.Parameters.Add(parameter5);
            command.Parameters.Add(parameter6);
            command.Parameters.Add(parameter7);
            command.Parameters.Add(parameter8);
            command.Parameters.Add(parameter9);
            command.Parameters.Add(parameter10);
            command.Parameters.Add(parameter11);
            command.Parameters.Add(parameter12);
            command.Parameters.Add(parameter13);
            command.Parameters.Add(parameter14);
            command.Parameters.Add(parameter15);
            command.Parameters.Add(parameter16);
            command.Parameters.Add(parameter17);
            command.Parameters.Add(parameter18);
            command.Parameters.Add(parameter19);
            command.Parameters.Add(parameter20);
            command.Parameters.Add(parameter21);
            command.Parameters.Add(parameter22);

It sems that problem is with owin.

When I enebale windows auth and disable allow anonymus - I need the windows login form. I need to login user based on his windows account automaticly and use your ABP roles managment, ABPAuthorize .... I have no idea how to solve this

Hello, I did it like you wrote. Burt htere is little problem, I must enable Windows Auth in project, but when I enable it in web config by:

<system.web>

&lt;authentication mode=&quot;Windows&quot; /&gt;
&lt;authorization&gt;
  &lt;deny users=&quot;?&quot; /&gt;
&lt;/authorization&gt;

I got this error:

Request filtering module is configured to deny the request, the query string is too long.

Detailed Error Information: Module RequestFilteringModule Notification BeginRequest Handler ExtensionlessUrlHandler-Integrated-4.0 Error Code 0x00000000

Requested URL	   http://localhost:6334/Account/Login?ReturnUrl=%2FAccount%2FLogin%3FReturnUrl%3D%252FAccount%252FLogin%253FReturnUrl%253D%25252FAccount%25252FLogin%25253FReturnUrl%25253D%2525252FAccount%2525252FLogin%2525253FReturnUrl%2525253D%252525252FAccount%252525252FLogin%252525253FReturnUrl%252525253D%25252525252FAc.......

Thanks for help

Hello, thanks.

I crated new issue there, and I found bug probably and his probable cause. See there: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/714">https://github.com/aspnetboilerplate/as ... issues/714</a>

Sample project was updated, link is on git issue.

BTW: Where would you paste code to auto SignIn when User starts the application ? I can get UserName from current thread and sign on using your method with db. But I´m not sure where paste this logic.

Thanks!

Hello, I created sample project with my problem and solution of it. Project is based on: ABP + ZERO + OWIN Mixed Auth: <a class="postlink" href="https://mega.nz/#!DUMgAD7A!tCX0MeHbYA88WGfj4clgcBE97HixrtaqPaH9N51d8f4">https://mega.nz/#!DUMgAD7A!tCX0MeHbYA88 ... aH9N51d8f4</a>

Please somebody have little time and test my SAMPLE auto windows login project, I will be pleased. I have problem with redirection loop when signin / sign out.

Thanks hikalkan !

Hello, I have question, how auto SignIn user with LDAP auth source. User no need password only his windows username, so if logged to windows is automticly logged to application / no login form need.

Where can i put this logic ? SignIn method in ABP need password / i do not have it because I can not get it from Windows...

Scenario:

1)User is logged in windows 2)User start brower with aplication 3) Aplication get windows username ang check if username exist in LDAP server 4) If it is OK - user is logged, / (ABP framework create record about user in AbpUser table (if not exist) -- this only for permission and role managment).

I have one idea to use Login(username, pass) method from Form base auth, and after user come to page and is logged by windows auth, perform this method in base constructor of controller using windows username (if LDAP auth do not have this username auth failded and user is redirected) Do you have better solution ? Is redirection possible in constructor of Controller ?

I also tried enable windows auth -> enable in web.config. But I got this error: Request filtering is configured on the Web server to deny the request because the query string is too long.

Is even posible to use windows auth with ABP and LDAP and Abp.User / Roles table ?

Thanks for help!

PS: Small question. What if I want to grand permissions for users in ActiveDirecotry db / in AbpUser is single record showed after login. Active Directory have xxxx users?

SOLVED by await before every async CALL :D :) I got DEDLOCK,more info: <a class="postlink" href="http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html">http://blog.stephencleary.com/2012/07/d ... -code.html</a>

Hello, I´m traing to do role permission managment. So I created custom permissions:

var administration = context.CreatePermission("Administration", new LocalizableString("Administration", "MND"));

            var pageManagement = administration.CreateChildPermission("Administration.PageManagement", new LocalizableString("PageManagement", "TT"));
            pageManagement.CreateChildPermission("Administration.PageManagement.DeletePage", new LocalizableString("Delteting", "TT"));
            pageManagement.CreateChildPermission("Administration.PageManagement.CreatePage", new LocalizableString("Creating", "TT"));
            pageManagement.CreateChildPermission("Administration.PageManagement.EditPage", new LocalizableString("Editing", "MND"));

            var roleManagement = administration.CreateChildPermission("Administration.RoleManagement", new LocalizableString("RoleManagement", "TT"));
            roleManagement.CreateChildPermission("Administration.RoleManagement.DeleteRole", new LocalizableString("Delteting", "TT"));
            roleManagement.CreateChildPermission("Administration.RoleManagement.CreateRole", new LocalizableString("Creating", "TT"));
            roleManagement.CreateChildPermission("Administration.RoleManagement.EditRole", new LocalizableString("Editing", "TT"));

I want to store information about granted permissions for ROLE in DB like you have it in ABP.Zero.

For that I used RoleAppService:

public async Task UpdateRolePermissions(UpdateRolePermissionsInput input)
        {
            var role = await _roleManager.GetRoleByIdAsync(input.RoleId);
            var grantedPermissions = _permissionManager
                .GetAllPermissions()
                .Where(p => input.GrantedPermissionNames.Contains(p.Name))
                .ToList();

            await _roleManager.SetGrantedPermissionsAsync(role, grantedPermissions);
        }

Input data: RoleId: X GrantedPermissionNames: Administration, Administration.RoleManagement, Administration.RoleManagement.DeleteRole

When i change permissions by UpdateRolePermissions , where are chnages strored ? If they are not stored what is purpose od this method ?

But when i call this method nothing is happen. In db (AbpPermissions) are not any changes. What I´m doing wrong ? Thnks !

Update: I notice, tahat after calling these method:
SetGrantedPermissionsAsync(role, grantedPermissions); GrantPermissionAsync(role, VARIABLE); ProhibitAllPermissionsAsync(role);

I also try this, but permission do not savr to db:/

public async Task UpdateRolePermissions(UpdateRolePermissionsInput input)
        {
            var role = await _roleManager.GetRoleByIdAsync(input.RoleId);
            var grantedPermissions = _permissionManager
                .GetAllPermissions()
                .Where(p => input.GrantedPermissionNames.Contains(p.Name))
                .ToList();



            if (role != null)
            {
                if (grantedPermissions.Count > 0)
                {

                    foreach (var item in grantedPermissions)
                    {
                         _roleStore.AddPermissionAsync(role, new PermissionGrantInfo(item.Name, false));
                         //_roleManager.GrantPermissionAsync(role, item);
                    }

               
                }
                else
                {
                     await _roleManager.ProhibitAllPermissionsAsync(role);
                }
            }

        }

DB table [AbpPermissions] completly freeze.. After call these methods in the sql managment studio cannot select items. ABP LOCK this table ? Some Bug ?

Showing 11 to 20 of 31 entries