Last post Jun 13, 2012 03:09 PM by biga
Jun 13, 2012 05:57 AM|biga|LINK
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">
<asp:TemplateField HeaderText="" SortExpression="TableName" HeaderStyle-HorizontalAlign="Center">
<asp:DynamicHyperLink ID="HyperLink1" runat="server" Font-Underline="false" ><%# Eval("DisplayName") %></asp:DynamicHyperLink>
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
How would I achieve this?
Jun 13, 2012 01:03 PM|sjnaughton|LINK
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.
Jun 13, 2012 03:09 PM|biga|LINK
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.