簡體   English   中英

如何在ASP.NET MVC中獲取另一個用戶的配置文件?

[英]How to get another user's profile in ASP.NET MVC?

我想在登錄時設置一個用戶時區的cookie。 AccountController.LogOn()似乎是最好的地方。 但是,我還不能在那里讀取用戶的配置文件,因為我猜你只能在方法完成時訪問配置文件。 所以,這段代碼返回一個空字符串:

Dim timeZone = HttpContext.Profile("TZ").ToString

用戶完全登錄后,上面的代碼將返回正確的TimeZone。

一種解決方案是讀取嘗試在AccountController.LogOn()中登錄的用戶名的配置文件:

ProfileCommon profile = Profile.GetProfile(username);  // FAILS

但是,這不起作用。

那么,如果他們沒有登錄,我如何閱讀給定用戶的個人資料?

這看起來並不明顯,但是獲得一個簡介:

ProfileBase profile = ProfileBase.Create(HttpContext.Profile.UserName, true);

返回現有實例。

除了Mathias的答案,您還可以將其轉換為您鍵入的配置文件:

ProfileCommon profile = (ProfileCommon)ProfileBase.Create(username, true);

此外, ProfileBase.Create的文檔位於MSDN上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM