I have users table containing all the user account details including a IsLoggedIn field with bit data type. I want to update any old rows with IsLoggedIn = 1 when a user starts new session before previous session expires. What is the best way to achieve this? Is it possible to do this with Trigger?
Thanks in advance..
You will have two things for sure.. 1) User ID and 2) Session Id in database.
Now when new session start (session_Start) event gets fire.. you can call one store procedure with logic and the logic will be
1) If there is not records with same userID do not do any update.
2) If there are any records with same userID update all of them with IsLoggedIn = 1.
You can extend this logic with TRIGGER as well and band it as per your need,.
Basically you need to track session_Start event and perform DB operations.
Trigger won't be the suggested solution as you need to handle login from UI. If there is going to be only a single login then Application_Start can be used. If there can be multiple logins then Session_Start is preferable. From there you can give a call to database and perform the respective actions.
Difference between the two is explained at : http://forums.asp.net/t/1230163.aspx/1?What+s+the+difference+between+Application_Start+and+Session_Start+in+Global+aspx+
Related
I am doing the user authentication where I have this case:
Read from vendor_type document and if it returns null(doesn't exist) then continue the transaction,
Create new user using .auth().createUserWithEmailAndPassword(email,password),
Read the new users ID,
Write to vendor_type document some of the new user's detail such as name, surname, userId -->> userId is the problem, how can I create a user and get the ID within a single transaction, can I even do that? ,
Take the newly created ID of the user, and create a new vendor document with that ID.
So far I don't have any code to post because I don't know if this is even gonna work so I didn't start. If you have any idea how to implement this, please let me know. The main issue is getting the user ID while still in the transaction.
At the time of writing, it is not possible to combine in one transaction the creation of a user through the createUserWithEmailAndPassword() method from the Auth service AND a write to the Firestore service.
They are two different services offered by Firestore and therefore you cannot combined calls to these two different services in one transaction.
How to save textbox value in the database
(Textbox value populated based on other textbox input value)
Solutions proposed in comments to the question seem to be reasonable, but I would offer one more if you don't mind. If TotalRate field's value is somehow important/vulnerable then I would never store it in database to avoid possible malicious manipulations from app users. In case there is some good reason/requirement to store calculated value in database I would go with calculation on the server side and handle it in onBeforeCreate and onBeforeSave model events:
// onBeforeCreate/onBeforeSave event handlers
record.TotalRate = record.PerHourRate * record.HoursNumber;
In my asp.net MVC application, I want to add a variable (a flag for the kind of system a user has) that can be accessed whenever a page loads or the user performs certain actions. I have decided to add a session variable for this (does this seem reasonable?), and I just need to grab the flag from a table in the database. My plan was to set the variable on Session_Start, but this doesn't appear to be the right way to do it as I need to query the database and I'm not sure if I should from the Global.asax. Where should I be populating this variable? Or is there a better way to do it?
Thanks in advance!
Session variable is a reasonable choice and session_start can be a place to get the value. However, if the value is user specific then in such case, you need user identity. Authentication will establish user's identity and not session start (both are independent in ASP.NET) - so instead of session_start, better bet would be Application_AcquireRequestState where you should check if user is authenticated or not and if yes, then check if your session variable has been set or not. If not set then you can get the value from database.
A slight variation would be on-demand loading i.e. create a wrapper method to get the flag value. Wrapper method will check if value has already been retrieved or not - if not then it will fetch it and cache the value in suitable store (e.g. session state).
Suppose if there are multiple sessions on single page and out of them I want to clear values of only one session then how can I achieve this. Will Session.clear() clear all sessions' value or it will create ambiguity because of multiple session?
You have only one session for one user at a time. If you clear the session, you only clear the session for the current user visiting the page, not for everybody.
Session.Clear(); // Remove all keys and values from the session state collection of current user
Session.Remove("SessionName"); //Will remove particular session variable of current user
I have a web application which has a Sql Server database on the backend. As the site will be rolled out to different clients (or different virtual directories in IIS), each client derivative of the site will use the same backend.
There is an admin page where text on the site can be changed (enter text in a listview, and choose the page to select where that text will show up, and also you can see company-specific details in the other listviews. As this is a shared database, that means a client can see each other's data.
What I am trying to do is store the accountId (a guid returned from the database from login_authenticate), and stick this into session. I then retrieve this on the admin page, and I want to use this value (But it's always 0000-0000 etc), to limit the records returned in the listview.
Is there an example of this? Also, how can I set the default value (this is in the where clause of SqlDataSource), to programatically what the account id is (so I can give me all records = what the current accountid is, or perhaps, what the login is - this is stored in the account table).
Thanks
This is what I tried.
What I am confused about, though, is whether the where clause, when using a session object, is getting an object that I have written the code to retrieve from the session, or an object I have only added but not retrieved. I get the accountID when logging in (verified via stepping in - obviously - or the login will fail).
I will try again with storing the object in session # the login page when I have just retrieved the accountid variable, and then retrieve it on another page.
For some reason I keep getting 0s so I will look at this in my application.
It sounds like your method should be working. I would follow a debugging process:
Check that you are getting the accountID value from the database. Print it on screen immediately after retrieving the value for the first time.
If this is working, store the value in the Session and immediately retrieve it, and check that you are getting the value back.
Create 2 test pages, one where you set the Session variable and another where you retrieve it.
I know this seems really basic, but the failure is being introduced somewhere in the above 3 places. If you can find which step fails, you will be able to fix it.