locked
public override bool CanDelete(IPrincipal principal) - Where to put? RRS feed

  • Question

  • User-299966805 posted
    I'm trying to create my own logic but I don't know how to override the virtual function. Where do I put this code?
     
    public override bool CanDelete(IPrincipal principal)
            {
                return true;
            }

    Sunday, July 15, 2012 3:06 PM

Answers

  • User-299966805 posted

    Not the most elegant but it resolved my problem until I understand the code above.

    New class file in app_code (Security.cs)
    
    namespace AuditDatabaseModel
    {
        
        public class Security
        {
            public static bool IsAdministrator(IPrincipal user)
            {  
                if (user.Identity.Name == "cooper88")
                    return true;
                else
                    return false;
            }
        }
    }
    
    Edited PageTemplates and added the following code
    
    <%@ Import Namespace="AuditDatabaseModel" %>
    
    <asp:DynamicHyperLink CssClass="btn ui-state-default float-left ui-corner-all ui-button" ID="DynamicHyperLink1" runat="server" Action="Edit" ><span class="ui-icon ui-icon-pencil "></span> Edit</asp:DynamicHyperLink> to
    <asp:DynamicHyperLink Visible='<%# table.CanUpdate(User) && Security.IsAdministrator(User)  %>'  CssClass="btn ui-state-default float-left ui-corner-all ui-button" ID="DynamicHyperLink1" runat="server" Action="Edit" ><span class="ui-icon ui-icon-pencil "></span> Edit</asp:DynamicHyperLink> 
    
    


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 17, 2012 4:50 PM

All replies

  • User-330204900 posted

    HI cooper88, your post is a little messed up, are you trying to implement a method of making individual ROWs not deletable based on a value?

    Monday, July 16, 2012 7:28 AM
  • User-299966805 posted

    I'm new to dynamic data but this is what I'm trying to do.

    <asp:LinkButton Visible='<%# table.CanDelete(User)  %>' SkinID="BtnForm" ID="LinkButton1" runat="server" CommandName="Delete" Text="Delete" OnClientClick='return confirm("Are you sure you want to delete this item?");'><span class="ui-icon ui-icon-trash"></span></asp:LinkButton>

    I want the button to hide if CanDelete(User) is false. I just want to hard code a few users who have delete privileges.

    Monday, July 16, 2012 10:59 AM
  • User-330204900 posted

    so all you want is to stop some users being abel to delete, I suggest you have a look at my article on securing DD here Securing Dynamic Data 4 (Replay)

    Monday, July 16, 2012 11:13 AM
  • User3866881 posted

    public override bool CanDelete(IPrincipal principal) - Where to put?

    What does this mean?Can you show us the existing codes you have?Which part do you want to override?

    Monday, July 16, 2012 10:01 PM
  • User-299966805 posted

    Thats my problem. The only code I have is 

    public override bool CanDelete(IPrincipal principal)         {             return true;         }

    but I don't know where to put it.

    Tuesday, July 17, 2012 4:47 PM
  • User-299966805 posted

    Not the most elegant but it resolved my problem until I understand the code above.

    New class file in app_code (Security.cs)
    
    namespace AuditDatabaseModel
    {
        
        public class Security
        {
            public static bool IsAdministrator(IPrincipal user)
            {  
                if (user.Identity.Name == "cooper88")
                    return true;
                else
                    return false;
            }
        }
    }
    
    Edited PageTemplates and added the following code
    
    <%@ Import Namespace="AuditDatabaseModel" %>
    
    <asp:DynamicHyperLink CssClass="btn ui-state-default float-left ui-corner-all ui-button" ID="DynamicHyperLink1" runat="server" Action="Edit" ><span class="ui-icon ui-icon-pencil "></span> Edit</asp:DynamicHyperLink> to
    <asp:DynamicHyperLink Visible='<%# table.CanUpdate(User) && Security.IsAdministrator(User)  %>'  CssClass="btn ui-state-default float-left ui-corner-all ui-button" ID="DynamicHyperLink1" runat="server" Action="Edit" ><span class="ui-icon ui-icon-pencil "></span> Edit</asp:DynamicHyperLink> 
    
    


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 17, 2012 4:50 PM