locked
Customising the main menu in a domain service dynamic data site RRS feed

  • Question

  • User-1336852631 posted

    I'm using DomainService with Dynamic Data to restrict access to certain entities in the model by the user's role.

    The Default.aspx page created for me includes the use of a dynamic hyperlink to present a menu that lists the links to entities that the user has access to:

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" RowStyle-Font-Names="Tahoma" RowStyle-Font-Size="Small"
            HorizontalAlign="Center" GridLines="None" CellSpacing="9" RowStyle-ForeColor="#718ABE" HeaderStyle-Height="0">
            <Columns>
                <asp:TemplateField HeaderText="" SortExpression="TableName" HeaderStyle-HorizontalAlign="Center">
                    <ItemTemplate>
                        <asp:DynamicHyperLink ID="HyperLink1" runat="server" Font-Underline="false" ><%# Eval("DisplayName") %></asp:DynamicHyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>        
        </asp:GridView>

    This works nicely in that if a user logs in with restricted access they only see the list of links they have access to.   However my list of entities is growing as I add more functionality to the site.  I need to be able to customise the main page and organise the many links in a logical manner.

    If I use normal hyperlinks in the Default.aspx page, then every user will see all the links and if they click on a link they don't have access to an UnauthorizedAccessException will be thrown.  I'd like to only show the links the user has access to in the customised Default.aspx.

    How would I achieve this?

    Wednesday, June 13, 2012 5:57 AM

Answers

All replies

  • User-330204900 posted

    see my http://csharpbits.notaclue.net/2010/02/sitemapprovider-for-dynamic-data-net-35.html sitemap provider I also have a version that uses my SecureMetaModel I can send it to you if you like.

    However if that is no good you could just write your own query on the scaffolded tables and get the security attributes and test for user having access.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 13, 2012 1:03 PM
  • User-1336852631 posted

    Thanks Steve,

    I looked through your sitemap provider and it does look to be what I'm after.  The key bit of code I was missing was:

    System.Collections.IList visibleTables = MetaModel.Default.VisibleTables;

    I like the way you've set up an attribute for the Menu structure - very nice.

    Wednesday, June 13, 2012 3:09 PM