C#.net - issues wiht code

I am finding that the below has some syntax errors...
if (Session("sessionTest_user") == 3)
            {
                if (string.IsNullOrEmpty(Session("SessionUsername")) | string.IsNullOrEmpty(Session("sessionPassword")))
                {
                    Response.Redirect("~/client/sys_messages/Customer_Failed_User_Login.aspx");
                    return functionReturnValue;
                }
            }

Open in new window

LVL 10
GlobaLevelProgrammerAsked:
Who is Participating?
 
viralypatelCommented:
The "OR" in your if statement should have two pipes i.e. ||
(You have just one as seen in the code)

if (Session("sessionTest_user") == 3)
            {
                if (string.IsNullOrEmpty(Session("SessionUsername")) || string.IsNullOrEmpty(Session("sessionPassword")))
                {
                    Response.Redirect("~/client/sys_messages/Customer_Failed_User_Login.aspx");
                    return functionReturnValue;
                }
       

Open in new window

    }
0
 
Dale BurrellDirectorCommented:
try using [] for accessing the session e.g. Session["item_index"]. If thats not it please post the error.
0
 
viralypatelCommented:
Also, Error      1      'System.Web.UI.Page.Session' is a 'property' but is used like a 'method'      

use Session["SessionUsername"] and Session["sessionPassword"]
0
 
Easwaran ParamasivamCommented:
Session("SessionUsername") the ( should be changed as []. I mean that should be as Session["SessionUsername"]. The or condition should be ||. Now it is mentioned as |. That is wrong.

Always typecast to integer while comparing with integer.

In Response.Redirect() method pass second parameter as false to avoid unwanted thread abort exception message.



if(Session["sessionTest_user"] != null)
{
if ( int.Parse(Session["sessionTest_user"]) == 3)
            {
                if (string.IsNullOrEmpty(Session["SessionUsername"]) || string.IsNullOrEmpty(Session["sessionPassword"]))
                {
                    Response.Redirect("~/client/sys_messages/Customer_Failed_User_Login.aspx", false);
                    return functionReturnValue;
                }
      }
}

Open in new window

0
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.

All Courses

From novice to tech pro — start learning today.