Recently do a small project with ASP, the user is not a lot, the function is not too complicated, but to do the right control when a little puzzled, so a small system if all do a large and complex authority control feel cost is not worth, intended to use the TreeView, according to different users, Load different user Web.sitemap files to achieve a simple sub-user, sub-module permissions control, specifically implemented as follows:
Start by building a simple user role table in the database to implement different user roles for different web.sitemap files
Add a different Web.sitemap file, and modify the Web. config file as follows:
The following configuration items are added under system.web:
<siteMap>
<providers>
<add name= "web" type= "System.Web.XmlSiteMapProvider" sitemapfile= "Web.sitemap"/>
<add name= "Mod1" type= "System.Web.XmlSiteMapProvider" sitemapfile= "Mod1.sitemap"/>
<add name= "mod2" type= "System.Web.XmlSiteMapProvider" sitemapfile= "Mod2.sitemap"/>
<add name= "mod3" type= "System.Web.XmlSiteMapProvider" sitemapfile= "Mod3.sitemap"/>
</providers>
</siteMap>
The following is the implementation of C # code:
public partial class Usercontrol_WebUserControlTreeView:System.Web.UI.UserControl
{
SqlConnection conn = new SqlConnection (system.configuration.configurationmanager.appsettings["Strcon"]);//Establish data connection
protected void Page_Load (object sender, EventArgs e)
{
Gettreeviewcontrol ();//menu with different permissions displayed
}
public void Gettreeviewcontrol ()
{
String myroleid=session["Roleid"]. ToString (). Trim ();
if (myroleid== "0")
{
Sitemapdatasource1.sitemapprovider = "Web";//Load All permissions Sitemap
}
if (Myroleid = = "1" | | myroleid== "2" | | myroleid== "3" | | myroleid== "4" | | myroleid== "5" | | myroleid== "6" | | myroleid== "7")//Team Send driver user
{
Sitemapdatasource1.sitemapprovider = "Mod1";
}
if (Myroleid = = "one" | | myroleid = = "one" | | myroleid = = "13")//Dispatch user
{
Sitemapdatasource1.sitemapprovider = "MOD2";
}
if (Myroleid = = "14")//Financial user
{
Sitemapdatasource1.sitemapprovider = "Mod3";
}
}
For non-strict permission control of the project, such as is fully enough, I hope you give their opinions and solutions
Go from: http://blog.csdn.net/baolei1981/article/details/2129836#0-qzone-1-531-d020d2d2a4e8d1a374a433f596ad1440 articles
Access to the sitemap file via SiteMapDataSource dynamic permission setting