3
Answers

Advice on using session variables

Rajesh Thampi

Rajesh Thampi

1y
748
1

Hello guys

We're developing a small extension for Oracle EBS/Oracle database using .Net Core 5 (VS 2019 for some specific reasons). As this application access is role based and hides multiple submit buttons based on user access levels, we were managing it using Session variables, across Razor pages. We're reading the user details from a table Home Controller -> Index method and setting up the session variables.

Please suggest ??

Answers (3)
2
Vishal Joshi

Vishal Joshi

247 7.8k 134.6k 1y

Hello Rajesh,

Instead of session variables, you can use Role-based Authorization and Authentication provided by Microsoft and its in-build functionality you can use. 

To Hide/Show buttons in UI you can use View-based authorization. it is a sub-part of Role-based Authorization and Authentication.

Check this link

https://learn.microsoft.com/en-us/aspnet/core/security/authorization/views?view=aspnetcore-7.0

below is the sample code to hide/show button

@if ((await AuthorizationService.AuthorizeAsync(User, Model, Operations.Edit)).Succeeded)
{
    <p><a class="btn btn-default" role="button"
        href="@Url.Action("Edit", "Document", new { id = Model.Id })">Edit</a></p>
}

Thanks

1
Aravind  Govindaraj

Aravind Govindaraj

318 5.9k 330.4k 1y

I would suggest creating a dynamic button(s) based on user-level access.

For instance, from the backend you will have role-based actions, the actions may be submit/view/edit. This action button supposes to be rendered dynamically with some generic button handler. So in future, if you want to add some more action, you can define it in the backend. 

From UI POV just need to call the function to render action buttons, which internally calls and creates action buttons accordingly. 

I hope it gives some idea. Thanks 

0
Rajesh Thampi

Rajesh Thampi

NA 128 6k 1y

Thanks Vishal & Aravind!

When I said role based, I was referring to roles inherited from Oracle EBS environments. Regardless, I think I got an idea about how to proceed.

Other than enabling and disabling controls, I have to share some information across razor pages. Got additional suggestions?

Thanks guys :)) ??