2013-09-27 17 views
0

我已經爲使用FubuMVC的Web應用程序實現了CurrentUserPropertyBinder(請參見下文)。與CurrentUserPropertyBinder相關的問題它不能始終記住用戶

public class CurrentUserPropertyBinder : IPropertyBinder 
    { 
     private readonly Database _database; 
     private readonly ISecurityContext _security; 
     public CurrentUserPropertyBinder(Database database, ISecurityContext security) 
     { 
      _database = database; 
      _security = security; 
     } 
     public bool Matches(PropertyInfo property) 
     { 
      return property.PropertyType == typeof(User) 
       && property.Name == "CurrentUser"; 
     } 
     public void Bind(PropertyInfo property, IBindingContext context) 
     { 
      var currentUser = //check database passing the username to get further user details using _security.CurrentIdentity.Name 
      property.SetValue(context.Object, currentUser, null); 
     } 
    } 

當我登錄到我的網站時,這工作正常。該CurrentUserPropertyBinder擁有所有它需要執行的任務的信息(即_security.CurrentIdentity.Name中有正確的用戶詳細信息)

當我嘗試並使用fineUploader導入文件(http://fineuploader.com/)打開其中標準fileDialog _security.CurrentIdentity.Name爲空。

它似乎沒有記得誰是用戶,我不知道爲什麼。它適用於我所有的其他路線,但後來我導入一個文件,它不會記住用戶。

請幫忙!由於提前

注意:我們正在使用FubuMVC.Authentication到

+1

您是否使用FubuMVC.Authentication或其他方法來驗證您的用戶? – ventaur

+0

我們使用FubuMVC.Authentication來驗證用戶 –

回答

2

我猜你的這個動作是從認證排除的用戶進行身份驗證;也許這是一個僅限AJAX的端點/動作。如果您在過去3個月左右更新了FubuMVC.Authentication,我認爲您不必看到該動作是什麼樣子,就可以輕鬆解決此問題。

您需要爲此操作啓用傳遞身份驗證。開箱即用,FubuMVC.Auth只需將IPrincipal連接到需要驗證的操作。如果您想從其他操作訪問該信息,則必須啓用傳遞過濾器。這裏有一些快速的方法來做到這一點。

  1. 裝飾你端點/控制器類中,此特定的操作方法,或輸入模型進行此操作與[PassThroughAuthentication]屬性選擇加入到直通AUTH。

    [PassThroughAuthentication] 
    public AjaxContinuation post_upload_file(UploadInputModel input) { ... } 
    

    [PassThroughAuthentication] 
    public class UploadInputModel { ... } 
    
  2. 改變AuthenticationSettings引導期間以匹配您FubuRegistry行動呼籲直通。

    ... 
    AlterSettings<AuthenticationSettings>(x => { 
        // Persistent cookie lasts 3 days ("remember me"). 
        x.ExpireInMinutes = 4320; 
    
        // Many ways to filter here. 
        x.PassThroughChains.InputTypeIs<UploadInputModel>(); 
    }); 
    

檢查/ _fubu /端點,以確保您的行動呼籲鏈應用了直通或認證過濾器。

+0

謝謝 - 這是一個很好的答案,但我仍然有同樣的問題。當我看着/ _fubu /端點時,它仍然在通過過濾器之前進行ModelBinding。所以我仍然有同樣的問題。我一定做錯了什麼? –

+0

快速提示 - @ventaur - 除了我上面的評論之外,應該注意的是我的輸入模型具有我嘗試綁定的屬性。 –

+0

Oy。這有點像Catch-22。我不是很積極,你可以在路由/輸入綁定之前對pass-through過濾器進行重新排序。我打算用這支大槍來打電話,所以我們可以給你最好的答案。 – ventaur