c# - Security script based on Global Group? -
i'm not sure if possible, i'd limit users specific areas of intranet site based on membership in specific global groups created in sql server.
for example, i've got following menu in asp:
<div class="clear hideskiplink" id="mainmenu"> <asp:menu id="navigationmenu" runat="server" cssclass="menu" includestyleblock="false" orientation="horizontal" backcolor="#cc3300"> <items> <asp:menuitem navigateurl="~/default.aspx" text="home" selectable="true" /> <asp:menuitem navigateurl="~/forms/frmcensuslist.aspx" text="census editing"/> <asp:menuitem navigateurl="~/forms/frmroster.aspx" text="roster editing"/> <asp:menuitem navigateurl="~/forms/frmreportmenu.aspx" text="reporting"/> <asp:menuitem navigateurl="~/about.aspx" text="about"/> <%-- <asp:menuitem navigateurl="~/webform1.aspx" text="test"/>--%> </items> </asp:menu> </div>
and following in code behind limits "security level" can see "about" page:
protected void page_load(object sender, eventargs e) { string path = request.apprelativecurrentexecutionfilepath; foreach (menuitem item in navigationmenu.items) { item.selected = item.navigateurl.equals(path, stringcomparison.invariantcultureignorecase); } // if user isn't admin, hide menu option string activeuser = system.web.httpcontext.current.user.identity.name; string securitylevel = activeuser.seclevel(); if (securitylevel != "admin") { menuitem mnuitem = navigationmenu.finditem("about"); // find particular item if (mnuitem != null) { navigationmenu.items.remove(mnuitem); } } }
seclevel() function created that's based on table of user's ids, maintaining table pain, plus future projects going pain compile original table, , easier if can based on existing global groups.
anyone got suggestions?
your global groups active directory security groups. can not difficulty using builtin asp.net role provider, web.config entries control groups/roles can see menu items, , binding menu control use web.sitemap file. of combined securitytrimmingenabled. ensure menu options shown to users in groups have defined. if these not ad groups, can still have create custom role provider check against sql server groups or use table have created.
your web.config location
entries end looking based on example provided, entries each of pages want allow user see:
<configuration> <location path="~/about.aspx"> <system.web> <authorization> <allow roles="admin"/> <deny users="*"/> </authorization> </system.web> </location> <location path="~/forms/frmcensuslist.aspx"> <system.web> <authorization> <allow roles="census,admin,etc"/> <deny users="*"/> </authorization> </system.web> </location> <location path="~/forms/frmroster.aspx"> <system.web> <authorization> <allow roles="admin,roster"/> <deny users="*"/> </authorization> </system.web> </location> ... </configuration> <system.web> <sitemap defaultprovider="xmlsitemapprovider" enabled="true"> <providers> <add name="xmlsitemapprovider" description="default sitemap provider." type="system.web.xmlsitemapprovider " sitemapfile="web.sitemap" securitytrimmingenabled="true" /> </providers> </sitemap> </system.web>
sample web.sitemap:
<?xml version="1.0" encoding="utf-8" ?> <sitemap xmlns="http://schemas.microsoft.com/aspnet/sitemap-file-1.0" > <sitemapnode url="~/forms/frmcensuslist.aspx" title="census" description="" roles="admin,census"> <sitemapnode url="~/forms/frmroster.aspx" title="roster editing" description="" roles="admin,roster"> <sitemapnode url="~/forms/frmreportmenu.aspx" title="reporting" description="" roles="admin,reports"> ... <sitemapnode url="~/about.aspx" title="about" description="" roles="admin"> </sitemap>
see this article more information
Comments
Post a Comment