2017-08-18 49 views
1

我們正在實施經過AAD認證的應用程序中的Html.AntiForgeryToken()。登錄工作正常,但當我們點擊主頁上的按鈕時,它需要調用控制器操作。以下例外情況未能通知控制器操作。任何想法來解決這個問題?使用Azure AD認證時,防僞驗證失敗

錯誤:

[HttpAntiForgeryException (0x80004005): The provided anti-forgery token was meant for user "[email protected]", but the current user is "".]

HTML:

using (Html.BeginForm("ExternalLogin", "Account", new { ReturnUrl = Model.ReturnUrl })) { 
      @Html.AntiForgeryToken() 
      <div id="LoginList"> 
       <p> 
        @foreach (AuthenticationDescription p in loginProviders) { 
         <md-button type="submit" class="btn facebook-theme-background" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">Login with @p.AuthenticationType</md-button> 
        } 
       </p> 
      </div> 
     } 

服務器端:它甚至沒有進入這個方法。當我評論ValidateAntiForgeryToken然後它進入。

[HttpPost] 
     [AllowAnonymous] 
     [ValidateAntiForgeryToken] 
     public ActionResult ExternalLogin(string provider, string returnUrl) 
     { 
} 

使用下面的兩個屬性進行身份驗證:

<add key="Tenant" value="xyz.onmicrosoft.com" /> 
<add key="Audience" value="<guid>" /> 
+0

歡迎來到堆棧溢出,請抽出時間通過[歡迎遊覽](https://stackoverflow.com/tour)瞭解你在這裏的方式(並獲得你的第一個徽章),閱讀如何[創建一個最小,完整和可驗證的示例](https://stackoverflow.com/help/mcve),並檢查[如何提出好問題](https://stackoverflow.com/help/how-to-ask ),所以你增加了獲得反饋和有用答案的機會。 – Valentun

回答

0

我試圖重現這個問題,但是失敗了。看來這個問題是相對於代碼而言的。您可以參考我的this link的代碼示例。

如果您仍有問題,可以分享一個可運行的演示來幫助重現此問題。