We have a Review System in place where I work. A manager selects an employee to review, which then sets the EmployeeID as a Session["EmpID"] variable. Now, the manager can enter in the information for the said employee.
Our Issue:
When a manager opens another tab or window in the browser (ie. Internet Explorer), searches for a different employee, it sets Employee #2 ID as the Session["EmpID"] variable, over-writing the first one. When the manager switches back to Employee #1 and enters information, they believe they are entering information for #1, however it enters it as #2 since they selected it last.
Does anyone have ideas to prevent this from happening?
When using tabbed browsing you actually use the same asp.net session, and therefore, if you don't uniquely seperate one page's cache from the others, you get the same data.
If your pages uses the session to store data, use a unique identifier (such as a GUID) as a prefix for the key. Store the guid in a hiddenfield or in the ViewState.
Maybe it'll suffice to store the EmpID in the ViewState. Then Tab1 will keep it's value even if Tab2 had another value.
ASP.NET session id shared amongst browser tabs
Way around ASP.NET session being shared across multiple tab windows
http://forums.asp.net/t/1227829.aspx/1
It sounds more feasible to store the empID in a hidden field/tag in the contents of the page. Save your record based off that string record = span.innerText , because that will be on the page not the session
Related
I am new to visual studio and databases. I have tried to find this answer on my own for several days, but I haven't found what I need, probably because I am not using the correct terms.
Short background: I am interested in building a web app that will take user input, store it, and then display that information in charts. Of course, this requires unique user logins.
What I want to understand is how information specific to a unique user is loaded into the site. So far, I've learned to pull static data from a database and put it in the website. However, that does not tell me anything about unique users' data when they log in with their account. So, when I log in to, for example, my online banking account or a site like Udemy, what tells the site to pull only my data? What's the key to displaying just my data?
If you have a resource instead, I'd be happy to read that. Thank you.
You need some form of a unique identifier for that particular user. Whether this is in the form of a user Id as an auto-incrementing primary key, a Guid, or something else, it should be unique to that user in that particular table.
From that unique user Id you should then be able (depending on the db), to find data associated with that unique user.
I've got a problem that may either be a limitation in my approach or asp.net web forms technology. The main driver for this solution is the simple fact that when users sit on an individual page for an extended period of time, they are redirected to our CAS server and back to the page itself which results in all of the form inputs being cleared as if the user did not enter any information (i.e. losing the ViewState/control state). With that being said I was exploring other options such as:
Using HTML localStorage to store a JSON string of all values on the page that can be parsed into an object and loaded into the form later if needed.
Even though this solution allowed me to store values on each page in individual key/value pairs (page instance 1 in localStorage[ID1], page instance 2 in localStorage[ID2] etc.), there was still a limitation on the server side of validating which page the user is saving. Right now I am using the session to maintain which form the user is viewing ie. the user is only associated with 1 page. To continue the example, the session information would result in the user being associated with either localStorage[ID1] or localStorage[ID2], not both ---which is precisely my problem. I need to communicate from the client-side which one page is to be saved. I've explored the following options, and come up with the following questions:
A static class that contains a static collection of objects on the server side storing which users have which pages open--> problem: communicating which page is actually being saved.
Dynamically rendering my save buttons with IDs that include an encrypted version of the page identifier at hand.
Storing the current value being edited in the Querystring
A cookie value that stores the value of the ID that the user wishes to change on post back-->how will the cookie get its value--especially when an ID is new (user is filling out form for the first time)?
I may be over complicating this and I know there is an easier way.
Many sites solve this problem by displaying a dialog when the user has sat on the page too long, asking if they still want to maintain their session. If the user doesn't click "Yes", then lose the session.
Another solution would be to permit a user who knows he's going to not use the page for a while to save the results so far and to restore them later, and continue.
Before proceeding with a technological solution, I'd try to find out why the users are sitting on the page so long. Whatever their reason is, you'll want to try to accommodate it if it's a good reason.
If the reason is "because we don't really care about your page and just didn't bother to close it", then your current solution works fine.
I just wanted to close out my own issue. I will resolve my problem by storing encrypted values in the query string to maintain page state. From there I will all values the user enters on the page within stringified json objects within localStorage. For example: page 1 with id: aa will have one key value pair within localStorage in the format [appName_pageId]. Page 2 with id bb will have a similar key value pair. If the user gets redirected to our CAS server and lands back on my page with all values cleared, I will be able to load the correct inputs from localStorage based on the value in the query string parameter (aa or bb). The important principle to remember here is that central control belongs on the server and distributed control should be done on the client.
I'm programming a Chat. Basically, I have a window (TextBox) where I want to display all users that are in the conversation at the moment but I do not wish to use a database.
So, I would need to keep my table of active users somewhere persistent something that does not get erased on refresh.
I looked in to Sessions. However, they expire and I can't keep the array of my active users in there. I also looked in Application Object and it seems this could solve my dilemma. However:
Say I call
String[] users = new users String[1000];
Application['users'] = users;
In my Page_Load() method, sure I can store the new user in to that table but then each page load will override the table and I will always show only one user but I guess implementing something along lines is isset() could solve that.
So I would need to keep my table of active users somewhere persistant
something that does not get erased on refresh.
A database is the solution for that.
The Application[] is actually a static variable, so its delete it when pool recycle, and also if you have more than one pool, than you have more than one common Application variables.
Read about application state: Using static variables instead of Application state in ASP.NET
See some other examples with asp.net chat:
http://www.codeproject.com/Articles/33817/Build-a-Web-based-Chat-using-ASP-NET-Ajax
I have a page where a user can enter information into text boxes and upon submitting the information is saved to the database and the information is added to a gridview that they can select and edit the records from.
They shouldnt ever, but if they delete a record hit the back button in a browser and then select the record in the gridview again they are going to get out of range error because the record no longer exists in the database.
So I am looking for ideas on how to best keep this scenario from happening. Any suggestions are appreciated and i will be checking frequently to provide any additional information as I know this might be a little vague.
You should always handle the case where a user selects a record that does not exist because of the inherit nature of web applications...the data is stale as soon as the user sees it.
Even if the user just displayed the page for the first time it is possible another user deleted the record just after the results were retrieved.
I would suggest checking to see if the record exists, prompting the user in some manner that the data is stale and refresh the list automatically.
You could temporarily disable the back button with javascript?
http://csharpdotnetfreak.blogspot.com/2009/04/disable-browser-back-button-javascript.html
Hi I have a RadGrid in my asp.net application and basically I am being asked to persist the sorting clicked on the header name throught out the user session so basically lets say I have the RadGrid with the following headings.
ID Name OrderNumber Shipped
So by default it is sorted in ASC order by name when you first arrive at the page, but now.. if the User resorts it by clicking on the Name heading again it will make it in DESC order. So what I am being asked to do is to make the web remember the sorting option no matter if the user navigates to a different page within the application. So when the user comes back he should see the gridview in the order he/she picked before leaving to another page within the appliacation.
How can I do this with a RadGrid, without using HttpCookie ?
I do not think I should show my code as it is the plain default set up of a RadGrid BUT if necessary I will just grab something and put it here, I am just not sure the best way to go about it.
Thank you
I don't think this is a feature that we should be looking from a third party control, rather than an implementation item when using it in a project.
So if the requirement is only to persist within the user session, HttpCookie or even ASP.Net session would work. But if the requirement is to maintain even across same users next log-ins, even database would be a go od option rather than putting the weight on the ASP.Net session or Cookie transferring client to server every time.