Implement Role based Forms Authentication using C# and VB.Net in ASP.Net

Last Reply on Sep 11, 2017 12:24 AM By AnandM

Posted on Sep 08, 2017 07:57 AM

https://www.aspsnippets.com/Articles/Implement-Role-based-security-using-Forms-Authentication-in-ASPNet.aspx i am using sir Mudassar Ahmed Khan's post in my project   i have two basic problem. 1. i wants to use custome login page without master page instead of asp login control (in this project login page is a contant page of master page). 2. when i login as user (with user role ) my menu show some admin page which should  only be visible to admin suppose i have menu item as account  ---->1. Creadit ---> 1. page1                2. page2                3. page3 account  ---->1. Debit ---> 1. page1                2. page2                3. page3

my sitemap.xml as follows

 

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="" title="Dashboard" description="" roles ="*">
        <siteMapNode url="~/Dashboard.aspx" title="Dashboard" description="Dashboard"  roles="*" />
      
      <siteMapNode url="javascript:;#" title="Admission" description="Admission" roles ="*">
        <siteMapNode url ="~/Admission/add-new-Admission.aspx" title="Add New Student" description="Add New Student"></siteMapNode>
        <siteMapNode url ="~/Admission/View-Admission.aspx" title="View Admission" description="View Admission"></siteMapNode>
      </siteMapNode>
      
      <siteMapNode url="javascript:;" title="Admin" description="Admin Page" roles ="Administrator">
            <siteMapNode url ="~/Admin/Users.aspx" title="Users" description="Users Page"></siteMapNode>
            <siteMapNode url ="~/Admin/Reports.aspx" title="Reports" description="Reports Page"></siteMapNode>
        </siteMapNode>
      
      <siteMapNode url="#1" title="Accounts" description="Accounts Page" roles ="Administrator">
        <siteMapNode url ="#2" title="Expences" description="Expences Page" roles ="Administrator">
        <siteMapNode url ="~/Accounts/Expences.aspx" title="Expences" description="Expences Page" roles ="Administrator" />
          <siteMapNode url ="~/Accounts/AddExpences.aspx" title="Add Expences" description="Add Expences Page" roles ="Administrator" />
          <siteMapNode url ="~/Accounts/ViewExpences.aspx" title="View Expences" description="View Expences Page" roles ="Administrator" />
        </siteMapNode>

        <siteMapNode url ="#3" title="income" description="income Page" roles ="Administrator">
      <siteMapNode url ="~/Accounts/income.aspx" title="income" description="income Page" roles ="Administrator" />
           <siteMapNode url ="~/Accounts/Viewincome.aspx" title="View income" description="View income Page" roles ="Administrator" />
          <siteMapNode url ="~/Accounts/Addincome.aspx" title="Add income" description="Add income Page" roles ="Administrator" />
        </siteMapNode>
   </siteMapNode>
    
        <siteMapNode url="~/Contact.aspx" title="Contact" description="Contact Us Page"  roles="*" />
    </siteMapNode>
</siteMap>

kindly help me

 

Posted on Sep 11, 2017 12:24 AM

Hi yogeshc,

You need to use Master Page for displaying the SiteMap throughout the site and if you don’t wish to use Master Page then you need to handle the SiteMap in each every page of the site which you are going to display to User or Admin.

If you simply don’t want to use Login Control then just replace Login Control with Two TextBoxes One for UserName and other for Password and One Button with OnClick Event which will call the ValidateUser method for verifying whether the user is authenticated one or not.

I would recommend you to make use of Master Page for displaying the Menus to the User as it is best way to approach because redundancy of code is removed while making use of Master Page.