Access to the sitemap file via SiteMapDataSource dynamic permission setting

Source: Internet
Author: User

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

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.