Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..

Me creating a web application using Asp.net with C#..

in that am using one login form but different users like admin,student

if admin ,logged in means i need to show all the controls in next page.

if student logged in means i need to hide few links and controls in next page..

here the next page is a Master Page..

How can i solve this problem Please Help me...
Posted
Updated 28-Jun-12 20:37pm
v2

According to your question.. you are talking about giving rights to the user according to their roles.

Raajendran, There are several possiblities for your question. Most simple is to manage a session for your user roles and according to the roles show and hide the controls in your Masterpage.

for example:

C#
if(loginid="admin")
{
session["userrole"]="Admin"
}
else if(loginid="Student")
{
 session["userrole"]="student"
}


Then in your Master page check whether the login user is admin or student and show or hide your links.


Thanks
Ashish

Make it solution if you got your answer, so other can refer to the solution too..
 
Share this answer
 
Comments
AshishChaudha 29-Jun-12 2:45am    
Why dont you rate the solution rajendran???
Raajendran 29-Jun-12 2:54am    
i dono how to rate
Raajendran 29-Jun-12 2:50am    
Thank u so much...

if am using two login pages means then how to do that...


in admin page i have 4 admin/Parent logins ..

in student login page i have more no of student logins..

how is it possible...




my innerpage is a master page


in that master page,,

if admins logged in from their login (admin login) page means .., i need to show all the links


if students logged in from their login page means i need to hide some links...
AshishChaudha 29-Jun-12 2:54am    
Dear no need of maintaing two login.maintain it through database. make a table name roles and assign that roles to admin and student. Check the role of a user before login.
Raajendran 29-Jun-12 2:56am    
thanks dude...
in design created two logins in flash...
so i need to take two logins..
Are you talking about Role based security here? If yes it is a huge topic. For time being what you can do is just check the role on the Page_Load of default page, store the role in a session or some state management technique and check the same on every page. Based on the values you enable or disable the controls in your pages. However this is a very vague or dirty way of doing it. You will need to understand about Role Based Security and it implementation in .Net Web Applications. Below articles will help you in understanding:
Role-based Security with Forms Authentication[^]
http://www.4guysfromrolla.com/webtech/121901-1.shtml[^]
Custom Membership, Role Providers, Website administration tool, and Role based access to individual files[^]
 
Share this answer
 
Comments
Raajendran 29-Jun-12 2:52am    
Thank u so much...
Vani Kulkarni 29-Jun-12 6:13am    
Glad it helped you!
Hi,
Like my friend ashish said, you can store user's role in your session and check the session for privileges.
But there is a simple way "Role based authorization" in asp.net to do this task. follow the links bellow:
http://msdn.microsoft.com/en-us/library/wce3kxhd.aspx[^]
ASP.NET authentication and authorization[^]
Form authentication and authorization in ASP.NET[^]

This may help you.
All the best.
--Amit
 
Share this answer
 
Comments
Raajendran 29-Jun-12 2:53am    
Thank U friend...
_Amy 29-Jun-12 2:56am    
Always welcome.. :)
Hello dude

There are many methods use like different user controls and check when a user lo-gin and apply an appropriate control.

Otherwise using membership to create role and user to use different menu displaying.

and may be helpful these links
http://www.johnpscott.co.uk/dotnettutorial/security/default.aspx[^]



http://equipmentpro.hubpages.com/hub/Lesson-3-Using-Menus-in-ASPNET-Development[^]


otherwise

Create two tables

MenuCategory with CategoryID, CategoryName,CategoryURL

Menu with MenuID,CategoryID, MenuName and MenuURL

Users with UserID, UserName

UserMenu with userID and MenuID

write a procedure like this

SQL
Create procedure Proc_GetMenuItems(@UserID int)
as
begin
   SELECT cat.CategoryName,men.MenuName,men.MenuURL
   FROM MenuCategory cat LEFT OUTER JOIN Menu men ON cat.CategoryID=men.CategoryID
        LEFT OUTER JOIN UserMenu umenu ON men.MenuID =umenu.MenuID
   WHERE UserID=@UserID;
END;


Execute the SP and get the menu items into a data reader/table and bind to a repeater or other data control and
add dynamically to the menu item.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900