2012-09-28 39 views
0

我想弄清楚我的程序的哪個部分導致此錯誤。因此,當一個用戶登錄到我的應用程序,所有當前用戶成爲該用戶

我有多個頁面都從PageBase繼承。他們從PageBase獲取用戶資料。這是從PageBase得到他們的用戶名稱的功能:

uiProfile = ProfileManager.FindProfilesByUserName(CompanyHttpApplication.Current.Profile.UserName) 

CompanyHttpApplication

public static CompanyHttpApplication Current 
    { 
     get { return (CompanyHttpApplication)HttpContext.Current.ApplicationInstance; } 
    } 

public CompanyProfileInfo Profile 
    { 
     get 
     { 
      return profile ?? 
        (profile = 
        ProfileManager.FindProfilesByUserName(ProfileAuthenticationOption.Authenticated, 
                  User.Identity.Name).Cast 
         <CompanyProfileInfo>().ToList().First()); 
     } 
     private set { profile = value; } 
    } 

不幸的是我沒有寫代碼的這一部分,程序員誰做了它不再在項目上。有沒有人可以向我解釋爲什麼當另一個用戶登錄(當我使用應用程序時),我成爲那個用戶?

+0

這是一個WEP應用..?如果是這樣你需要得到Page.UserIdentity.Name.Split(「\」)創建一個字符串[]將其賦值給 – MethodMan

+0

詢問原作者。 – Bernard

回答

4

應用程序實例在每個請求 - 應用程序級別上共享。

您希望會話級別 - 每個用戶都有自己的實例。

使用HttpContext.Current.Session而不是ApplicationInstance

(下面的代碼原有的重命名,並增加了一個屬性,更清晰,隨時根據需要進行調整。)

public static CompanyHttpApplication CurrentApplication 
{ 
    // store application constants, active user counts, message of the day, and other things all users can see 
    get { return (CompanyHttpApplication)HttpContext.Current.ApplicationInstance; } 
} 

public static Session CurrentSession 
{ 
    // store information for a single user — each user gets their own instance and can *not* see other users' sessions 
    get { return HttpContext.Current.Session; } 
} 
+0

這爲我工作。感謝您花時間回答我的問題 – proseidon

5

HttpContext.Current.ApplicationInstance是全局共享的。它不是每個用戶。因此,您的共享配置文件會立即覆蓋您在新用戶登錄時原先設置的任何配置文件。

+1

同意+1。該操作可以嘗試將User.Identity.Name傳遞給當前HttpContext,而不是將HttpApplication.Current.Profile.UserName傳遞給FindProfilesByUserName – dash

+0

Roger。謝謝。我不太清楚這一切的東西是如何工作的(我是相當新的ASP.net),但我一定要得到這個改變了,希望更多地瞭解它的過程中 – proseidon

相關問題