Learning about Permissions

Source: Internet
Author: User
I think permissions are complicated. I wrote a simple code that reads the permission list of this user after logging on and put it in a hashtable, put it in a session and compare whether the menu or File Permission is in hashtable. I don't know if this idea is true or not. I hope you will give your comments.

Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

Public partial class default5: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

}
Protected void button#click (Object sender, eventargs E)
{// Indicates whether to log on
Session ["username"] = "admin ";
Hashtable ht = new hashtable ();
Ht. Add ("survey management", "1 ");
Ht. Add ("news management", "2 ");
Ht. Add ("member management", "3 ");
// Permission table
Session ["Popedom"] = HT;
}
Protected void button2_click (Object sender, eventargs E)
{

Session. Abandon ();
}
Protected void linkbutton#click (Object sender, eventargs E)
{
If (session ["username"]! = NULL)
{
If (hashtable) session ["Popedom"]). Contains ("Investigation Management "))
{
Linkbutton1.text = "Investigation Management permission ";
}

}
Else
{
Linkbutton1.text = "you do not have the investigation management permission ";
Page. clientscript. registerclientscriptblock (page. GetType (), "DD", "alert ('You have no investigation management authorization');", true );
}

}
Protected void linkbutton2_click (Object sender, eventargs E)
{
If (session ["username"]! = NULL)
{
If (hashtable) session ["Popedom"]). Contains ("news management "))
{
Linkbutton2.text = "news management permission ";
}

}
Else
{
Linkbutton2.text = "You are not authorized to manage News ";
Page. clientscript. registerclientscriptblock (page. GetType (), "DD", "alert ('You have no news managementauthorization');", true );
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.