Roles, Permissions asp.net c # sql server

1

Good, I would like you to help me, I'm doing programming language asp.net c # and sql server roles and user permissions:

I have these following tables in Sql Server:

Table Roles

ID_Roles    Rol_Cargo   Rol_Estado
  1       ADMINISTRADOR    1
  2        LOGISTICA       1
  3           LIMA         1
  4            JOS         1

User Table

ID_Usuario  Usu_Username    Usu_Pass    Usu_Estado
  1           pflores        123456         1
  2           CMARALLANO     123456         1
  3           DCOLLANTES     123456         1
  4            DYLLESCAS     123456         1

Table User_Roles

ID_Usuario_Roles    ID_Usuario  ID_Roles
    1                      1     1
    2                      2     2
    3                      3     3
    4                      4     4

Table Menu

ID_Menu       Men_Nombres                      Men_Estado
1         Registrar Servicios Red Lima            1
2         Registrar Servicios Red Provincia       1
3         Registrar Nuevos Suministros            1
4         Reporte Todos los Meses                 1
5         Pago Servicio Red Lima                  1
6         Pago Servicio Red Provincia             1

Table Menu_Roles

ID_Menu_Roles   ID_Menu ID_Roles
    1              1       1
    2              2       1
    3              3       1
    4              4       1
    5              5       1
    6              6       1
    7              1       2
    8              2       2
    9              3       2
   10              4       2
   11              5       3
   12              6       4

For what I am developing is according to the user who enters the menu should be shown according to the type of user.

For which I have this stored procedure that is entered.

ALTER procedure [dbo].[SP_ValidarUsuario]
@username varchar(350),
@llave varchar(350)
as
begin

SELECT a.Usu_Username,d.Men_Nombres FROM Usuario a
inner join Usuario_Roles b
on a.ID_Usuario=b.ID_Usuario
inner join Menu_Roles c
on b.ID_Roles=c.ID_Roles
inner join Menu d on c.ID_Menu=d.ID_Menu
WHERE a.Usu_Username=@username AND Usu_Pass=@llave --a.Usu_Username='pflores' and a.Usu_Pass='123456'   --@username AND Usu_Pass=@llave

end

so when I login with the user I already capture what menu should go in this case for example I put the administrator and this is the result of the procedure in the image:

But when I do it in the asp.net c # in the menu I do not know how to make it visualize the truth I would like you to help me

    
asked by PieroDev 29.08.2017 в 22:08
source

1 answer

3

In some project I did something similar, for that what I did was that in the table that you call "Menu Table" is added a column that contains the page, link or procedure that should be called when selecting the menu option and already with this additional field you call the stored procedure and store it in a table or list and with this build the menu is very simple.

In the place where you are going to locate the menu, put the following:

<asp:Literal ID="Literal1" runat="server" Mode="PassThrough"></asp:Literal>

and in the code behind load the query that already works in a datatable (I guess that part is clear) and after that you build a string with the "items" menu, finally that string you send to the literal object :

DataTable menu = GetData(query);
        string mppal = "";
        for (int i = 0; i < menu.Rows.Count; i++)
        {
            mppal += "<li><a runat=\"server\" href=\"" + menu.Rows[i][2].ToString() +
                "\" style=\"color: #FFFFFF\">" + menu.Rows[i][1].ToString() + "</a></li>";
        }
        Literal1.Text = "<nav> <ul id=\"menu\">" + mppal + "</ul> </nav>";
    
answered by 29.08.2017 / 22:18
source