2

目前,我有一個Controller與需要授權的Index()操作方法:顯示節點,如果其行爲被標記爲[授權(角色=「管理員」)

public partial class CustomerController : BaseDocumentStoreController 
{ 
    [Authorize(Roles = AccountController.Administrator)] 
    public virtual ViewResult Index() 
    { 
     ... 
    } 

    ... 
} 

有了這個地方,在Mvc.sitemap各節點將不會在麪包屑顯示:

<mvcSiteMapNode  title="Customer"   controller="Customer" action="Index" 
        resourceKey="Customers" clickable="true" > 

    <mvcSiteMapNode title="Customer Add"  controller="Customer" action="Add" 
        resourceKey="Add" /> 
    <mvcSiteMapNode title="Customer Create" controller="Customer" action="Create" 
        resourceKey="Add" /> 
    <mvcSiteMapNode title="Customer Edit" controller="Customer" action="Edit" 
        resourceKey="Edit" /> 
    <mvcSiteMapNode title="Customer Update" controller="Customer" action="Update" 
        resourceKey="Edit" /> 
    <mvcSiteMapNode title="Customer Delete" controller="Customer" action="Delete" 
        resourceKey="Delete" /> 
    <mvcSiteMapNode title="Customer Details" controller="Customer" action="Details" 
        resourceKey="Details" /> 
    <mvcSiteMapNode title="Customer Search" controller="Customer" action="Search" 
        resourceKey="Search" /> 

</mvcSiteMapNode> 

我想要的是顯示這個節點反正...

假設用戶未通過身份驗證。所以我想麪包屑顯示此:

Home > Customers > Add 

目前這隻能說明:

Add 

如果用戶點擊客戶節點,他將被重定向到登錄查看... OK , 沒關係!

我試圖實現自己的SiteMapVisibilityProvider以下these steps

public class SiteMapVisibilityProvider : ISiteMapNodeVisibilityProvider 
{ 
    ... 
} 

在調試我只能看到節點婁索引節點,也就是,在我目前的情況下,只有添加節點出現了。代表Index操作方法的節點沒有顯示在調試會話中。

有什麼辦法實現我想要的?

回答

3

問題很可能在於DefaultAclModule,它隱藏了當前用戶無法訪問的所有節點。如果您不想要該功能,可以通過在web.config的站點地圖提供程序中將securitytrimming設置爲false來禁用該功能。

您還可以通過實施自定義AclModule來更改功能。

+0

你是對的!嘗試在web.config中設置'securityTrimmingEnabled =「false」',它工作的很好!在閱讀Maarten的這篇博客文章(MvcSiteMapProvider創建者)之後:http://blog.maartenballiauw.be/post/2008/08/29/Building-an-ASPNET-MVC-sitemap-provider-with-security-trimming.aspx I現在瞭解'Authorize'屬性如何與'MvcSiteMapNode'節點一起工作。我不知道的概念是你在答案中提到的安全修整。非常感謝你的隊友...... :) – 2012-04-23 02:11:52

+0

順便說一句:我看到你的優秀系列帖子叫做Inside the MvcSiteMapProvider。真正有用的人...這一個只是談論你提到的AclModule:http://xharze.blogspot.com.br/2012/04/inside-mvcsitemapprovider-part-4.html偉大的工作,並繼續保持下去。 – 2012-04-23 02:37:10

相關問題