CMSPUBLISHINGSITE#2にリストアイテムイベントレシーバItemDeleting方法で削除をキャンセルすることはできません
-
18-09-2019 - |
質問
私はイベントレシーバを使用してリスト項目の削除をキャンセルする問題が生じていますSharePoint 2010のRCを使用します。私のコードは、エラーメッセージを設定し、呼び出し元のスレッドにエラーを投げ、SPItemEventPropertiesのキャンセルプロパティを設定し、発射されます。このアプローチは、しかし、消去法で使用した場合、私は、デバッガでコードの火を見ることができ、更新/追加する方法で正常に動作しますが、アイテムがまだサイトのごみ箱に移動されます。
さらに、私はSTSADMからではなく、サーバーの全体管理を経由して「チームサイト」テンプレートから作成したサイトから「CMSPUBLISHINGSITE#2」テンプレートから作成したサイトで、この動作を見ています。
不正動作するコードは、次の
public override void ItemDeleting(SPItemEventProperties properties)
{
if (!(properties.UserLoginName == "SHAREPOINT\\system"))
{
try
{
throw new CreatorIdAliasingException("Please contact support if you feel a release web site has been inappropriately assigned to your organization.");
}
catch (CreatorIdAliasingException ex)
{
properties.Cancel = true;
properties.ErrorMessage = ex.ToString();
properties.InvalidateListItem();
throw;
}
}
}
は、参考のため、同一符号をItemAdding方法に含まれると期待どおりに動作している。
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
if (!(properties.UserLoginName == "SHAREPOINT\\system"))
{
try
{
throw new InvalidCreatorIdException("Please contact support to add a known URL to your list of release web sites.");
}
catch (InvalidCreatorIdException ex)
{
properties.Cancel = true;
properties.ErrorMessage = ex.ToString();
properties.InvalidateListItem();
throw;
}
}
}
解決
私はあなたのビジネスロジックの一部として例外を使用しないためにあなたをお勧めします。例外は高価であり、唯一の通常のロジックによって処理されない例外的な場合に使用すべきである。
代わりに、このようなものを使用します:
public override void ItemDeleting(SPItemEventProperties properties)
{
if (properties.UserLoginName.ToLower().CompareTo("sharepoint\\system") != 0)
{
properties.Cancel = true;
properties.ErrorMessage = "Some error has occured....";
}
}
そして、ところで、あなたはおそらく、あなたが経験している、この動作を参照してください理由であるイベントハンドラ内で、追加の例外をスローされます。
所属していません StackOverflow