2015-01-02 5 views
12

「メンバをオーバーライドしながら、違反継承セキュリティルール」を投げ、私はMVCプロジェクトに付属しているデフォルトのアカウント・コントローラ・レジスタ機能を使用しています:登録が私の学校のプロジェクトのために

// POST: /Account/Register 
[HttpPost] 
[AllowAnonymous] 
[ValidateAntiForgeryToken] 
public async Task<ActionResult> Register(RegisterViewModel model){ 
    if (ModelState.IsValid){ 
     var user = new ApplicationUser(){UserName = model.UserName}; 
     var result = await UserManager.CreateAsync(user, model.Password); 
     if (result.Succeeded){ 
      await SignInAsync(user, isPersistent: false); 
      return RedirectToAction("Index", "Home"); 
     } 
     else{ 
      AddErrors(result); 
     } 
    } 

    // If we got this far, something failed, redisplay form 
    return View(model); 
} 

しかし、私は、登録ボタンをクリックしたとき私の形で私が取得:Security accessibility of the overriding method must match the security accessibility of the method being overriden

は、私は少しを検索し、[SecurityCritical]を追加すると、それを修正する必要がありますが、あなたは非同期タスクにそれを追加することができないことを発見しました。

[TypeLoadException: Inheritance security rules violated while overriding member: 'Microsoft.AspNet.Identity.TaskExtensions+CultureAwaiter`1<T>.UnsafeOnCompleted(System.Action)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.] 
    Microsoft.AspNet.Identity.UserManager`2.CreateAsync(TUser user, String password) +0 
    Admin.Controllers.<Register>d__8.MoveNext() +198 
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93 
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 
    System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +84 
    System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +17 
    System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32 
    System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50 
    System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225 
    System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10 
    System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34 
    System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26 
    System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100 
    System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 
    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54 
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39 
    System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +28 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54 
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29 
    System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 
    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9657896 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 

[assembly: SecurityRules(SecurityRuleSet.Level1)]を追加すると、それを行う必要がありますが、またそれはこれが唯一の(統合パイプラインでバージョン4.0を実行している)私の公開サーバー

スタックトレース上にある

動作しないことがわかりました

+1

例外のスタックトレースは何ですか?あなたのクラス継承のように聞こえますどこかに 'public'がある' private'があります – trailmax

+0

@trailmaxスタックトレースを追加 – Kiwi

+0

別のフレームワークバージョンをテストする新しいプロジェクトを作成しようとしましたか? 'UserManager.CreateAsync'メソッドを変更しない限り、あなたの信頼レベルが何らかの形で、またはフレームワークのバグと異なる場合を除いて、なぜこれが起こっているのかわかりません。 – Justin

答えて

0

アセンブリは、GACの下に登録された場合にのみ完全信頼を与えられます。アセンブリがプライベートアセンブリの場合、部分信頼と透過(example of transparent behavior)です。アセンブリがprivateアセンブリなので、Dot Net CLR[SecurityCritical]を無視します。

したがって、privateアセンブリを引き続き保持し、それを中程度の信頼で実行する予定がある場合は、[SecurityCritical]メンバをオーバーライドしたりアクセスしたりすることはできません。

How to install an assembly into the Global Assembly Cache in Visual C#

+0

あなたに完全に従っていません。もう少し説明できますか?なぜ、GACのためにストックアセンブリが設定されないのか。それともデフォルトでは行われていないものですか? – Kiwi

+0

@Kiwiエラーが表示された理由を説明しました。私の解決方法は次のとおりです。1-使用されたアセンブリの信頼レベルを変更するか、または2 - 中程度の信頼(オーバーライド)の違反を考慮します。 –

関連する問題