J
Jeff Hagins
I have written a DataRowChangeEventHandler to act as
a "security" filter based on the current users "role". The
event handler needs to be able to reject/cancel Inserts to
the ADO.NET DataTable (these inserts are the results of a
Select against the dataSource using the Fill method on a
SqlDataAdapter).
I've tried throwing an exception inside the handler, which
doesn't appear to do anything. I've also tried calling
RejectChanges on the row. This seems to work, but also
seems to leave an invalid row in the table in a "Detached"
state, which causes things like AcceptChanges to blow up
later on.
I suspect I'm just going about this the wrong way, but
haven't seen an example anywhere of how to prevent a Row
from being added to a DataTable.
My code is shown below -- does anyone know what
the "right" way is to do this?
Thanks in advance,
Jeff
private void
FrameworkRowAddedSecurityMonitor(object sender,
IFrameworkTableSecurityEvent e)
{
if (e.Action == DataRowAction.Add)
{
if
(e.SecurityObject.DataType != null)
{
if
((e.SecurityObject.AccessMask &
ContentManager.FW_ACL_PERMISSION_READ) == 0)
{
// Option 1
DataRow
row = (DataRow) e.SecurityObject;
row.RejectChanges();
// Option 2
throw (new
ContentManagerSecurityException("Access
Denied",e.SecurityObject,ContentManager.FW_ACL_PERMISSION_R
EAD,e.SecurityObject.AccessMask));
}
}
}
}
a "security" filter based on the current users "role". The
event handler needs to be able to reject/cancel Inserts to
the ADO.NET DataTable (these inserts are the results of a
Select against the dataSource using the Fill method on a
SqlDataAdapter).
I've tried throwing an exception inside the handler, which
doesn't appear to do anything. I've also tried calling
RejectChanges on the row. This seems to work, but also
seems to leave an invalid row in the table in a "Detached"
state, which causes things like AcceptChanges to blow up
later on.
I suspect I'm just going about this the wrong way, but
haven't seen an example anywhere of how to prevent a Row
from being added to a DataTable.
My code is shown below -- does anyone know what
the "right" way is to do this?
Thanks in advance,
Jeff
private void
FrameworkRowAddedSecurityMonitor(object sender,
IFrameworkTableSecurityEvent e)
{
if (e.Action == DataRowAction.Add)
{
if
(e.SecurityObject.DataType != null)
{
if
((e.SecurityObject.AccessMask &
ContentManager.FW_ACL_PERMISSION_READ) == 0)
{
// Option 1
DataRow
row = (DataRow) e.SecurityObject;
row.RejectChanges();
// Option 2
throw (new
ContentManagerSecurityException("Access
Denied",e.SecurityObject,ContentManager.FW_ACL_PERMISSION_R
EAD,e.SecurityObject.AccessMask));
}
}
}
}