Currently I have a webpart on a document library which programmatically filters the view using the user's personal properties.
It works fine until I simulate multiple users (2 browsers) accessing this library. If I access on the document library with User A, it shows records only related to User A, which is correct. But now if I refresh the page with User B, instead of showing records related to User B, it is showing User A's records. If I refresh it again on User B, it will revert back to B's records.
I did some testing and found out that when I go to filter under "Library >Modify View" instead of refreshing the page, the filter is using User A's information. But when I debug the program, it is always updating the view with the correct user's information.
This is the code for the webpart
SPContext.Current.Web.AllowUnsafeUpdates = true; SPList currentList = SPContext.Current.List; SPView view = currentList.DefaultView; view.Query = "<Where><Contains><FieldRef Name='" + currentList.Fields["info"].InternalName + "' /><Value Type='Text'>" + personProperties.UserProfileProperties["StaffID"] + "</Value></Contains></Where>"; view.Update();
What is causing the problem and how can I fix this?
I am taking a wild guess here but I think it might be because SPView's Update method is non thread safe? So when two users are concurrently accessing the list or library, one will override another's update query. But I have yet to find a way to solve this.