2009-12-01 27 views
4

我有一個Flex-WebORB-Asp.NET應用程序。登錄時,有一個AuthenticationHandler實現了一個WebORB接口:Asp.NET的主要WebORB HttpHandler

IPrincipal CheckCredentials(string username, string password, Request message); 

所以我創建一個Principal並返回它。 WebORB使用Principal來檢查遠程方法調用的認證和授權。

var principal = new GenericPrincipal(new GenericIdentity(user.id.ToString()), new[] { "admin" }); 
return principal 

現在,在這一點上,如果我檢查HttpContext.Current.User.Identity是什麼,它是一個WindowsIdentity。

到目前爲止這麼好。當後來,遠程呼叫通過的WebORB做,我通過調用獲取登錄的用戶的ID:

Thread.CurrentPrincipal.Identity.Name 

所以我猜的WebORB確保線程的標識設置每個遠程調用。

問題是,當我調用HttpHandler(檢索圖像)時,我也嘗試獲取Thread.CurrentPrincipal.Identity.Name的登錄用戶的ID,但這不起作用。可能是因爲使用HttpHandler,WebORB不會起作用。

你會如何解決這個問題,以便我可以在兩種情況下以相同的方式獲取登錄用戶的ID?把它放在會話對象中?你能改變HttpContext.Current.User.Identity嗎? HttpContext.Current.User.Identity是不是應該和Thread.CurrentPrincipal.Identity.Name一樣?

ps:用戶不在Active Directory中。

回答