English 中文(简体)
How to affect single child nodes when Security Trimming a SiteMap?
原标题:

I have a ASP.Net site, in which I m trying to use Windows Authentication and Active Directory roles to limit access to some pages. I ve looked at a tutorial page from Scott Gu, but I can t quite achieve what I want.

I m ignoring the root node in my SiteMapDataSource. I want to show the "Documents" node to all users, but limit the display of the "Search" and "Upload" roles to 2 different roles. I am in the "DOMAINvalidrole" but not in the "DOMAINmadeuprole". With the sitemap and web.config below, I am getting all the nodes displayed. If I remove the roles="*" from the "Documents" node (as suggested by Scott Gu), I get no nodes displayed.

Is there a way I can limit the display of individual child nodes without having to write custom code?

This is my sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
    <siteMapNode url="~/Default.aspx" 
                 title="Home">
        <siteMapNode title="Documents" roles="*">
            <siteMapNode url="~/Documents/Search.aspx" 
                         title="Search Documents" 
                         roles="DOMAINvalidrole" />
            <siteMapNode url="~/Documents/Upload.aspx" 
                         title="Upload Documents" 
                         roles="DOMAINmadeuprole" />
            <siteMapNode url="~/Documents/Publish.aspx" 
                         title="Publish Documents" />
        </siteMapNode>
        <siteMapNode title="Users" roles="*">
            <siteMapNode url="~/Users/Search.aspx" 
                         title="Search Users" 
                         roles="DOMAINvalidrole" />
        </siteMapNode>
    </siteMapNode>
</siteMap>

And this is the relevant section of my web.config:

<authentication mode="Windows"/>
<authorization>
    <allow roles="DOMAINvalidrole"/>
    <deny users="*"/>
</authorization>

<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
    <providers>
        <add name="XmlSiteMapProvider"
             description="Default SiteMap provider."
             type="System.Web.XmlSiteMapProvider"
             siteMapFile="Web.sitemap"
             securityTrimmingEnabled="true" />
    </providers>
</siteMap>
最佳回答

Sorted - you need to set up authorization to the page in the Web.config file like this:

<location path="Documents/Upload.aspx">
    <system.web>
        <authorization>
            <allow roles="DOMAINmadeuprole"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>

I had tried this with the path "~/Documents/Upload.aspx", but that didn t work - it needs to be a path relative to the config file.

Also, I had to put a URL in my sitemap nodes, like this:

<siteMapNode title="Documents" roles="*" url="Made-Up.aspx">

This stopped everything disappearing, although I have no idea why. I m not displaying the URL so any made-up one does the trick.

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签