ASP.NET - two login control on different pages

Asked By Reena Jain on 06-Apr-11 07:36 AM
Hello,

I am using asp.net 2008. i have created one admin folder and there i am putting admin pages and one login form with login control. on root folder i am using another login form with other login control. For admin  section login control is set by asp settings table means from membership and for user login is set by user table. i have also set the permission in web config file for admin to 'admistrator' and for root folder pages to all (*) users.

I want to autheticate the admin with admin id and password (first login control). and for user its user id and password. so i am using login view control but every login view control is working for admin and user both. how to use different login view for different login control. means if admin login he can see pages available to him only and same for user

thanks in advance
dipa ahuja replied to Reena Jain on 06-Apr-11 08:20 AM
i think You don't  required two logins for that..

You can manage the admin part and users part using the role management 

add the line in web.config :

<roleManager enabled="true"/>

you can hide menu or pages using the role of the logged in users :
        
//hyperlink of adming page admin.aspx .. hide if user with anther role is logged in
        if (User.IsInRole("admin"))
    {
      Hyperlink1.Visible = true;
      ad.Visible = true;
    }   
    else
    {
      
Hyperlink1
.Visible = false;

      ad.Visible = false;         }

and suppose if user try to open webpage by writing manually for that you can use the Location Tag in the web.config file :
 <location path="admin/Adminmenu.aspx">
    <system.web>
    <authorization>
      <deny users="?" roles="user"/>
      <allow users="*" roles="admin"/>
    </authorization>
    </system.web>
  </location>
  
 
now if local user try to access the page of admin he will be redirected to login page to login with admin username and password..

hope this will help you!