2017-03-12 17 views
0

.netコア1.1.1を使用してアプリケーションを覗きます 現在のユーザーがタグヘルパーの管理者ロールのメンバーであるかどうかを確認する必要があります。私は例外を持っているコメントのない文字列isAdmin = await userManager.IsInRoleAsync(currentUser, "admin")を残す場合.net core IsInRoleAsync 'System.ObjectDisposedException'

public override async void Process(TagHelperContext context, TagHelperOutput output) 
    { 
    currentUser = await userManager.GetUserAsync(actionContextAccessor.ActionContext.HttpContext.User); 
     isAdmin = await userManager.IsInRoleAsync(currentUser, "admin"); 
    } 

:TagHelperのコンストラクタは、Processメソッドをオーバーライドし

public MyTagHelper(UserManager<User> UserManager, IActionContextAccessor ActionContextAccessor) 
    { 
     userManager = UserManager; 
     actionContextAccessor = ActionContextAccessor;    
    } 

ある「タイプの未処理の例外 『をSystem.ObjectDisposedException』システムで発生しました。 Private.CoreLib.ni.dll "

理由を理解できません。 ありがとうございます。

答えて

0

プロセスは同期メソッドであり、非同期voidとすると、関数が終了するのを待たないことを意味します。代わりに、ProcessAsyncをオーバーライドしてタスクを返す必要があります。試してみてください:

public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) 
{ 
    currentUser = await userManager.GetUserAsync(actionContextAccessor.ActionContext.HttpContext.User); 
    isAdmin = await userManager.IsInRoleAsync(currentUser, "admin"); 
} 
+0

ありがとうございます。できます。 – gikerix

+0

あなたは歓迎ですが、ここに誰かに感謝する最善の方法は、彼らの答えを受け入れ、それをupvoteすることです。 (私の答えの左側にある緑色の矢印と上向き矢印をクリックしてください) –