473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C#.net web hide tab and link in non-Admin Accounts

Hi!

I am using C#.net. I need to hide a specific tab and link to a normal user.
Only Administrator can see this tab and link. Can I know the code on how to do this?

Thank you very much
Sep 11 '08 #1
1 1927
PRR
750 Expert 512MB
"I am using C#.net. I need to hide a specific tab and link to a normal user.
Only Administrator can see this tab and link. Can I know the code on how to do this?"

Depending on whether you have web application or windows application .. you will have to look into Generic Identity and Generic Principal or WindowsIdentity and WindowsPrincipal ..Assuming your roles are defined..and you are using web application ... take a look at this ...

Expand|Select|Wrap|Line Numbers
  1. using System.Security.Principal;
  2. // Populate the roles from database or elsewhere ... you could use just one roles array
  3. public string[] rolesAdmin=new string[]{"admin","spueradmin"};
  4. public string[] rolesOther = new string[] { "user", "user2" }; 
  5.  
  6.  
  7. //onload
  8. if (!IsPostBack)
  9.         {
  10.             call1("admin");
  11.         }
  12.  
  13.  //  onload 
  14.  
  15.     private void call1(string username)
  16.     {
  17.         GenericIdentity myid = new GenericIdentity(username); //username .. here you have verified that user is authenticated .. now you are gonna authorize him 
  18.         //GenericPrincipal myprin = new GenericPrincipal(myid, rolesAdmin);
  19.  
  20. // here you could get the roles from database.... 
  21.         GenericPrincipal myprin = new GenericPrincipal(myid, rolesOther);
  22.  
  23.  
  24.  
  25.         //if(username=="admin" || username=="sadmin")
  26.         if (myprin.IsInRole("admin"))
  27.         {
  28.             Button1.Enabled = true;
  29.         }
  30.  
  31.         else 
  32.         {
  33.             Button1.Enabled = false;
  34.         }
  35.  
  36.     }
  37.  
  38.  
this is just a sample code .. look into msdn for more details .. For ajax tabs ... you could make it visible or disable the tabs.... Still its important to disable the parent control or child controls that only a admin can see... dont just make controls invisible ... disable them as well...
Sep 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Atz | last post by:
<a href="" onmousedown="setTimeout('status=\'Hide\'',5000)" onmouseover="window.status='Hide'; return true"> send link </a> I use this for hidding link path in status bar. This is working fine...
2
by: Mark | last post by:
Hi, I need to be able to have five different links and when when someone clicks to show row 2, row 1 automatically hides. Right now all i can figure out is a link that will show but then you...
5
by: Mark | last post by:
Hi - I have a function which shows/hides a <div> on my page - this appears to oinly work in IE, but I also need it to work in Netscape 7.1. My function is in my head: function openIt(faq) {...
10
by: oLE | last post by:
I would like to add some javascript to show/hide a certain row of a table. The first row of the table contain the hyperlink that calls the javascript the second row is the one i want to show/hide...
0
by: Efkas | last post by:
I have a full custom application with some widged extending Controls like Label and PictureBox. I build a menu with these widgets. When I click on one of them, it calls a function to display...
1
by: Shapper | last post by:
Hello, I have this code line inside an ASP.Net Repeater: <a href='<%# DataBinder.Eval(Container.DataItem, "link") %>'><%= readMore %></a> What I need to do is: 1. Show readMore value if <%#...
15
by: dee | last post by:
Hi, I'm curious why MS decided to have Transfer hide the target page's url invisible? Any guesses ? Thanks. Dee.
4
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
13
by: nokan | last post by:
Hello! I'm trying to secure pdf-files from users that are not logged in on a site. What I have tried now is to make a .htaccess file in the directory where the pdf's are with "deny from all"...
1
by: dylanb | last post by:
Hi can anyone tell me how to alter this script so it will works on classes and id's; <script> function showhide(id){ if (document.getElementById){ obj = document.getElementById(id); if...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.