Conditional webform controls

J

Jerod Guida

I am fairly new to asp.net and am using webforms in vb.net. I have read a
lot about authorization to entire pages using role-based security, but I
haven't seen much in regard to role-based security for controls within a
page.

For example, say that I want an aspx page to show a link for "Maintenance"
when the user "John" is logged in but not for anyone else. All users have
authorization to see the aspx page (set in web.config), but how does someone
go about the process of conditionally displaying the link? My question is
generic in that I don't specifically care about the link, rather, I am
looking for something that could be applied to any type of control
(textboxes, buttons, etc) within webforms.

Thanks in advance,
Jerod
 
A

Arthur Dent

You could use either of the following methods, where you have any control
named c:

c.Visible = User.Identity.Name = "AllowedUserName"
- or -
c.Visible = User.IsInRole("MyAllowRole")

You could then combine this with a user control, or a panel to make a whole
block of the page show/hide, instead of just one control.

HTH.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top