Apply JAVASCRIP and STYLE code only for exact user Role? _AdminLayout.cshtml

1 week ago
4.50

i want to apply javascript and style code but only for special user role Id in _AdminLayout.cshtml

but my code must be applied only for this user role id, not the admin. because admin usually has all roles.

how can i do it?

something like this

if user role id is 15 then { my code goes here }
1 week ago
Put this code on the top,
var customerRoleIds = await customerService.GetCustomerRoleIdsAsync(currentCustomer);
    var applyCustomScript = false;
    if(customerRoleIds.Contains(15))
    {
        applyCustomScript = true;
    }


and then depends on the variable applyCustomScript  field, add this code portion of html body
@if(applyCustomScript)
    {
        <script>
            console.log("Test");
        </script>
    }
1 week ago
rmahbub63 wrote:
Put this code on the top,
var customerRoleIds = await customerService.GetCustomerRoleIdsAsync(currentCustomer);
    var applyCustomScript = false;
    if(customerRoleIds.Contains(15))
    {
        applyCustomScript = true;
    }


and then depends on the variable applyCustomScript  field, add this code portion of html body
@if(applyCustomScript)
    {
        <script>
            console.log("Test");
        </script>
    }


thank you for your reply.
yes, that is what i really need, but my problem is that i need to apply my code only for this user, but not for the admin.
i want to apply my code only for Registered (id 3), but Administrator also has Registered role.
what can i do in this case?
1 week ago
arthur_shneider wrote:

yes, that is what i really need, but my problem is that i need to apply my code only for this user, but not for the admin.
i want to apply my code only for Registered (id 3), but Administrator also has Registered role.
what can i do in this case?

change logic part into this,
if (customerRoleIds.Contains(3) && !customerRoleIds.Contains(1))
        {
            applyCustomScript = true;
        }

it will be applicable for all customer who have role 3 and don't have role 1