Session variable error

I am doing the following but gets below error

     <cfif err_Login EQ " ">
           <cfset session.Username = #form.txt_UserName#>
          <cflocation url="usersMenuForm.cfm">  

In usersMenuForm.cfm the following message is displayed when doing <cfoutput>#session.Username#</cfoutput>

Element USERNAME is undefined in SESSION
Errol FarroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


do you have session management turned on in your application.cfm?

<cfapplication name="yourApp" sessionManagement="yes">
Errol FarroAuthor Commented:
Still getting the same message. Here is my code. Must cfapplication be entered in all the forms

<cfapplication name="usersValidateForm" sessionManagement="yes">
      <cfif err_Login EQ " ">
             <cfset Session.Username = #form.txt_UserName#>
            <cflocation url="usersMenuForm.cfm">  

In ="usersMenuForm.cfm" I have

<cfoutput> #Session.Username#</cfoutput>  
This is a duplicate of the other question here:


As I answered there:

 well, are you sure it is being set?

Really the code should look like this:

<cfif Len(Trim(err_Login)) EQ 0>
       <cflock scope="session" timeout="10" type="exclusive">
           <cfset session.Username = form.txt_UserName>
        <cflocation url="usersMenuForm.cfm">  

Also if you don't have session management turned on in your application.cfm file or if you have cookies disallowed then this will not work.

If cookies are disallowed you can try

<cflocation url="usersMenuForm.cfm">   --> <cflocation url="usersMenuForm.cfm" addtoken="yes">  
Try this,
<cfdump var="#session#">

Just type that in at the bottom of a page to see all of your session variables.

Also to keep yourself from going nuts, try to put a else statement when trouble shooting.  There might be a problem with the IF statement that is not setting your user name.  So else <cfset session.Username = junglebook>  If you see your else statement then you know it is something wrong with your if statement not the application, or it's sessions.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.