coldfusion session variable not defined - session

Ive been monitoring the log files of my application recently and its got quite a few references of a certain session variable apparently not existing.
I Know its been defined, as its been part of the application since we built the very first version around 4 or 5 years ago.
So what Im wondering is... if CF throws an error stating that the session variable is undefined. is this an example of a race condition in CF ?
Or is there any other thing that could be causing this generally ?
The session variable is defined when the user logs in as part of their login credentials using a struct containing the users profile information.
At the point of adding an item to the users shopping cart, we must leverage a particular key of this struct to post to a legacy system.
From time to time we see that this variable is not defined. Which is really strange as its definitely there because if it wasnt, the struct that it resides in wouldnt exist.
This application is an application that has been migrated from CF 8 to CF10 and it could be the reason as to the cause of the issue.

Related

coldfusion session variable disappearing

I have a variable, session.acclevel, which is set during the login process (the program is login2.cfm).
<cfset session.acclevel = logdata['LOGACCESS'][1]>
The values can be N,R,W,A,M, and they are retrieved with query name = "logdata" from a table which I'm calling XXX here. If the login is successful, login2.cfm redirects to program navbar.cfm
<cflocation url = "navbar.cfm?welc=yes">
which is a set of dropdown menus, rather like a dashboard. Depending on the value of session.acclevel navbar shows more or fewer options. The session.acclevel variable is also used throughout the system to control various user activities.
All this was working fine, and then it suddenly stopped working -- session.acclevel was fine when navbar started up, but disappeared as soon as any selection was made. Yet, no code had been changed. The only thing I had changed was to alter the MySql table definition of the acclevel` variable type:
alter table XXX change LogAccess LogAccess enum('A','W','R','N','M');
to add the option 'M' to the enum. I did not chnage any data in that table, and I made no changes to the coding anywhere.
I double checked the timeouts (I am using system admin defaults), and tried without success to trace where the variable was getting lost. I closed and reopened the browser, without fixing anything.
Finally I went to the administrator and changed session management to J2EE -- and that fixed it. session.acclevel is now staying put.
Could someone explain what was going wrong there? I would like to know in case this defect in the ColdFusion session management is caused by weak code that I could avoid, or in case it later breaks under J2EE management.

Laravel Multi Domain Session

I am not a superb developer, so I guess the problem I did run into is just to big for me.
I have a project where I have different subdomains for the current language. When I login a user it is logged only for the current subdomain. So when I login at "en.Aproject.com", and then go to "de.Aproject.com", the user will not be logged in. They don't share the session. I already tried to modify the 'domain' => null, in app/sessions.php. But when I change the value here the Login doesn't work at all. Then everytime a new Session-row is created in the DB and Laravel seems not to recognize them.
Is the current domain saved somehow in the session identifier? Is it possible to use one session for different domains? I found some stuff about OAuth and Single sign-on but I can not handle it by myself.
I was thinking about (when logging in and the credentials are correct) calling a script via Ajax, which should log in the user for all needed domains. But I would have to do the same for logging out.. And I will probably have a lot of domains. The project will have one base page and several subprojects (all with the different languages). Like this
mainproject.com
en.mainproject.com
de.mainproject.com
...
Aproject.com
en.Aproject.com
de.Aproject.com
...
Bproject.com
en.Bproject.com
de.Bproject.com
...
So it would just feel wrong to log in the user to like 20 different pages and create 20 sessions... It would feel better to just use one session for all of them.
Okay, I hope you understand the problem and someone already had the same problem and found a solution. Thanks!!!!!!!! greets. gerti
Background info.. I am using Laravel 4.2
Now I just tried something, maybe it helps someone. Actually point 2 is weird to me (see below)
I display these 3 things:
Session::getId()
Auth::getName()
var_dump(Session::all())
I display them on "de.Aproject.com". Here I am logged in.
And i display them on "en.Aproject.com"... Where I am still logged out (which I want to fix :D )
The value of Session::getId() is different on both sides. Thats the problem I guess, they should share the same.
The value of Auth::getName() is the same on both sides (login_82e5d2c56bdd0811318f0cf078b78bfc). Which I don't understand. Why does the second page have this value when i am not logged in?
The value of Session::all() is ["login_82e5d2c56bdd0811318f0cf078b78bfc"] => string(17) "test#test.de" on the first site, on the second its empty. Thats correct.
Since the default Laravel authentication system uses cookies to manage the session, you actually need to login the user on each subdomain you're going to use. To avoid that, you can use another session driver like database.

Is there a better way than using session variables to access an object anywhere in an application?

I am working with ASP.NET MVC 3.0. I have a page with an action link that makes appear a window in which you can adjust a certain value. Once the new value is sent to the database, an extern application deals with the value and send the result back to that database. I want the action link to be disabled while the extern application is doing her job. The page I am working on is refreshing automatically with some AJAX calls. The date when the extern application finished her last adjustment on a value is kept in the database. I first thought I could use session variables to store the date time of when the action link was pressed (because I need it through all the application) and then enable the action link when the adjust time is greater than the time when the action link was pressed, but I heard it was bad practices. Does someone have another solution?
Since you are already using the database - query the database to check the current status. If your application is restarted - a session value would be lost unless you are using a state server (ie sql server) to manage state- unless you don't care if its lost upon restart. You can use session and save yourself database calls - but the database is a bit cleaner and doesn't suffer from the same issue. If you do end up using the session, don't spread that session value all over your code, simply have a single method that reads or sets it (same with the db solution as well)

Core Data Migration error message "'Model does not contain configuration 'XYZ'.'"

I have a Managed Object Context to which I add two different SQLite stores. I use Configurations in the Mananged Object Model to assign certain entities to one store and other entities to the other. The Configurations are called "UserDB" and "MainDB".
Everything works okay until I try to use automatic migration. After creating a new Managed Object Model version, and adding a new attribute to one of the entities in the UserDB Configuration, I get an exception when adding the old version store (for the UserDB related store) to the store coordinator: 'Model does not contain configuration 'UserDB'.' I can find no hits for this error on Google. Anyone out there using multiple stores with Configurations? Anyone have an idea what I might be doing wrong?
The stack looks like this:
objc_exception_throw
-[NSManagedObjectModel isConfiguration:compatibleWithStoreMetadata:]
-[NSStoreMigrationPolicy sourceModelForStoreAtURL:metadata:error:]
-[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:]
-[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:]
-[MyAppDelegate persistentStoreCoordinator]
This looks like a bug with migration+configurations. I was able to work around the problem by going through the same motions and passing nil for configuration when calling addPersistentStoreWithType. The migration happens, and then I can make a new persistent store coordinator and add the stores again with the proper Configuration string arguments.
This is the second configuration related bug I've run into. Not a well tested feature apparently.
I had the same problem. The fact pattern was identical and the error message the same. It turned out, however, to be the result of my own mistake.
Let's say the old model was Blah.xcdatamodel and the new Blah 2.xcdatamodel. I had started making changes to Blah before realising my mistake and creating Blah 2. I then used my version control system (Git) to revert to the old Blah and then recreated Blah 2. Everything looked right. But I must have done something wrong in the reversion process, because when I thought to double check that Blah.xcdatamodel in my current project folder was really the same as Blah.xcdatamodel in the project folder I used to build the previous version of the app (fortunately I always keep a zipped archive of the project folder for each released version as I don't fully trust version control systems), I found that they were in fact different, albeit that they looked identical in XCode. The file size was different, for instance.
I substituted the old Blah into my current project folder, and lo and behold it all went perfectly, without any need for the workaround described by Ken.
I am not saying that Ken had necessarily made a similar mistake, but if you do encounter this message it is at least worth confirming that the model you are migrating from is REALLY the model that was used to create the data in question.

How do I access a asp.net session variable from APP_CODE?

I have seen lots of posts here and elsewhere stating that one can access session variables from app_code. I want to access an already created session.
this code errors out because of a null exception.
string myFile = HttpContext.Current.Session["UploadedFile"];
this creates a null session variable.
System.Web.SessionState.HttpSessionState Session = HttpContext.Current.Session;
It looks like I can create a new session variable but not access an already created one. Anyone have any idea what might be giving me problems?
I was having ths same problem, but I was able to fix it because I controlled where in the event lifecycle I was attempting to leverage HttpContect.Current.Session... it makes a difference because Session isn't available, for example, on construction.
Maybe that will help you.

Resources