Question : asp.net: How to determine if the type of user logging in... is an Admin or a User

asp.net: How to determine if the type of user logging in... is an Admin or a User

I  have included my code which is in the main.master page ->

what I am seeing is the same menu items for each Admin or uSer see images.

When Logged in as admin I see the Summary report ...which is correct and as admin I can access it.

When I login as a user, I aslo see the Summary report...which I should not be seeing. And if i click on it, it give me a url error.
Again the the Summary report should not be listed for Users???


this is my code:

  <asp:LoginView ID="LoginView2" runat="server">
                      <LoggedInTemplate>
                        <RoleGroups>
                          <asp:RoleGroup Roles="Administrator">
                          <ContentTemplate>
                                    <span class="style25"><a href="../Admin/SummaryRpt.aspx">Sales Report</a></span><br class="style25" />
                                    </span>
                          </ContentTemplate>
                         </asp:RoleGroup>

                         <asp:RoleGroup Roles="User">
                            <ContentTemplate>
                                 <p class="style26">
                                    <span lang="en-us">
                                    <span class="style25"><a href="../User/updateprofile.aspx">Update Profile</a></span><br class="style25" />
                                    <span class="style25"><a href="../User/resetpassword.aspx">Change Password</a></span><br class="style25" />
                                    <span class="style25"><a href="../User/newequipment.aspx">New Equipment</a></span><br class="style25" />
                                    <span class="style25"><a href="../User/UpdateEquipment.aspx">Update Equipment</a></span><br class="style25" />
                                </p>    
                            </ContentTemplate>
                         </asp:RoleGroup>
                       </RoleGroups>  
                      </LoggedInTemplate>
                   </asp:LoginView>
Attachments:
 
User Login
User Login
 
 
Admin Login
Admin Login
 

Answer : asp.net: How to determine if the type of user logging in... is an Admin or a User

What method of authentication are you using? forms, basic or other?

if basic or forms then you can hide the link and or protect the page using this

if not My.User.IsInRole("administrators") then
    'do something like redirect to menu or hide the link
end if

note. in forms you will have to set the httpcontext of the user in order to check their groups

Random Solutions  
 
programming4us programming4us